fix(react): recreate SelectionArea instance when props change#262
Merged
Conversation
Owner
|
Thank you for this high-quality PR, I'll have a look at it soon! :) |
Fixes simonwep#226 The React SelectionArea component had an empty dependency array in its useEffect, which meant the component never reacted to prop changes. This is unlike the Vue implementation which uses watchEffect to auto-track dependencies. Changes: - Add configuration props (boundaries, document, selectables, startAreas, container, behaviour, features) to the useEffect dependency array - Use useRef for callback props to avoid unnecessary instance recreation when only callbacks change - Use useMemo with JSON.stringify for object props (behaviour, features) to provide stable dependency comparison - Forward remaining HTML attributes to the container div via rest props
1b5f17b to
74a60f7
Compare
simonwep
approved these changes
Feb 15, 2026
74a60f7 to
4fc6b8b
Compare
Owner
|
I'll have to do some work to be able to release a new version since it's been a while and I have to update all dependencies first... :) Made some minor changes to support preact and fix an issue in how options are resolved. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Fixes #226
The React component had an empty dependency array in its
useEffect, which meant the component never reacted to prop changes. This is unlike the Vue implementation which useswatchEffectto auto-track dependencies.Changes
boundaries,document,selectables,startAreas,container,behaviour,features) to the useEffect dependency arrayuseReffor callback props to avoid unnecessary instance recreation when only callbacks changeuseMemowithJSON.stringifyfor object props (behaviour,features) to provide stable dependency comparisonBehavior
Before: Changing any prop after initial mount had no effect - the SelectionArea instance was never updated.
After:
Notes
As mentioned in the issue, the core module doesn't support dynamic option updates, so recreating the instance is the correct approach. This matches the Vue implementation's behavior.