Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update to React 17 #4057

Merged
merged 5 commits into from
Dec 3, 2024
Merged

Update to React 17 #4057

merged 5 commits into from
Dec 3, 2024

Conversation

tillprochaska
Copy link
Contributor

@tillprochaska tillprochaska commented Dec 2, 2024

This PR updates React from version 16 to 17. I had to slightly adjust code in two places due to features that were deprecated and also had to remove the react-truncate package as it hasn’t been updated to support recent React versions (which in that particular case is a good thing anyway as the same effect provided by the package can be achieved with pure cSS). Apart from that, the update is fairly straight-forward.

…`componentWillReceiveProps`

The latter has been deprecated and will stop working in React 18
…ops`

The `EntityViewer` component displays a list of fields for the following entity properties:

1. Feature properties (no matter whether the property has a value or not)
2. Properties with at least one value
3. Properties manually added by the user using the "Add a property" select

The previous implementation kept a list of all visible properties (1-3) in the component state. It used the `componentWillReceiveProps` hook to reset this list when a user selected a different entity. The new implementation keeps only the selected properties (3) in the component state. Featured and non-empty properties (1+2) can be derived from the `entity` property at render time. In order to reset the list of selected properties when the user selects a different entity, we use the entity ID as a key. When the entity ID changes, React instantiates a new component (with fresh state) rather than reusing the component rendered for the previous entity.
The previous implementation computed this once when the component is instantiated, this type of state is a common source of bugs. The new implementation computes the list at render time which has a small, but negligible overhead, and is simpler.
… as `react-truncate` hasn’t been updated for a long time and is incompatible with React 17+.
@tillprochaska tillprochaska force-pushed the update-react branch 2 times, most recently from e53b773 to f985274 Compare December 2, 2024 21:57
@tillprochaska tillprochaska changed the title Update react Update to React 17 Dec 2, 2024
@tillprochaska tillprochaska marked this pull request as ready for review December 3, 2024 11:08
@tillprochaska tillprochaska requested a review from stchris December 3, 2024 11:09
@tillprochaska tillprochaska merged commit 3c154e3 into develop Dec 3, 2024
1 check passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant