-
Notifications
You must be signed in to change notification settings - Fork 2
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
task/WG-432 rework hooks, maps and feature tree to minimize renders #339
task/WG-432 rework hooks, maps and feature tree to minimize renders #339
Conversation
…hanges-filter-changes
…hanges-filter-changes
…hanges-filter-changes
…hanges-filter-changes
Moving functions out of the render cycle and into memoized component properties. Changes account for feature selection time from 700ms to 20ms
Prevent unnecessary re-renders by removing searchParams dependency as selectedFeatureId is enough. Also useMemo for selectedFeatureId determination
Ensure that setSelectedFeatureID is not dependent on selectedFeatureId
Make some optimizations in Map and FeatureFileTree
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
const prevDataRef = useRef<FeatureCollection | undefined>(undefined); | ||
const prevStateRef = useRef<{ pending: boolean; error: boolean }>({ | ||
pending: false, | ||
error: false, | ||
}); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just curious, I wonder if react query's keepPreviousData
could be of use here?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good idea; that got me working on different approaches. I tried that way and some others but it got tricky with this due to all the different cases and uses, so I ended up keeping some state (with zustand) that could provide data/status for useCurrentFeatures. While maybe not the best (or final) solution, now all the use scenarios are fixed. I couldn't manage getting all the cases to work with react-query and my half-baked interpretation of checking all inactive/active queries.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sounds good. I've had good luck with ensureQueryData
, prefetching, and suspense queries to ensure data is present regardless of status, but not sure if that's applicable here off the bat
Co-authored-by: Sal Tijerina <[email protected]>
…hanges-filter-changes
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
Overview:
This PR reworked hooks, maps and feature tree to minimize renders and optimize things.
The main issues we noticed were:
The fixes were:
useCurrentFeatures
hook so that provides stable reference to the latest featuresuseFeatureSelection
hook to ensure that setSelectedFeatureID is not dependent on selectedFeatureIdOff-topic change:
PR Status:
Related Jira tickets:
Summary of Changes:
Testing Steps:
Notes:
TODO