-
Notifications
You must be signed in to change notification settings - Fork 843
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
Add useMemo util for htmlIdGenerator + update EuiDataGrid's IDs to not change on every rerender #5133
Conversation
As a note, I only updated |
Preview documentation changes for this PR: https://eui.elastic.co/pr_5133/ |
- that creates a memoized ID, preventing the issue of re-randomized IDs on every component change
…props) + update EuiCollapsibleNav as an example of real-world usage
9e8f013
to
1009e4c
Compare
👋 Hey y'all! I ended up squashing in my changes in a rebase, since there were many of them after our recent team discussion.
Thanks y'all! Locally, I'll keep beavering away at converting more |
Preview documentation changes for this PR: https://eui.elastic.co/pr_5133/ |
👋 Re-pinging for review since this is potentially blocking @breehall's PR! |
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.
I mainly just looked at the new hook and it's associated docs. Had a couple of suggestions.
src-docs/src/views/html_id_generator/html_id_generator_example.js
Outdated
Show resolved
Hide resolved
src-docs/src/views/html_id_generator/html_id_generator_example.js
Outdated
Show resolved
Hide resolved
src-docs/src/views/html_id_generator/html_id_generator_example.js
Outdated
Show resolved
Hide resolved
src-docs/src/views/html_id_generator/html_id_generator_example.js
Outdated
Show resolved
Hide resolved
Preview documentation changes for this PR: https://eui.elastic.co/pr_5133/ |
Co-authored-by: Caroline Horn <[email protected]>
704c3c8
to
0a2a20a
Compare
Preview documentation changes for this PR: https://eui.elastic.co/pr_5133/ |
Preview documentation changes for this PR: https://eui.elastic.co/pr_5133/ |
Preview documentation changes for this PR: https://eui.elastic.co/pr_5133/ |
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.
Love how simple this hook turned out to be!
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, only checked in Chrome though and only the Docs of the new hook.
src-docs/src/views/html_id_generator/html_id_generator_reuse.js
Outdated
Show resolved
Hide resolved
- update comment from ref to memo - Skip EuiFlexGroup
I just did another quick QA pass and noticed all but 1 of the CodeSandbox links on the HTML ID generator demos are broken because they export named components instead of a default function 🙈 I'll fix that here shortly! |
Preview documentation changes for this PR: https://eui.elastic.co/pr_5133/ |
- Changed exports from named exports to default in order for demos to work in CodeSandbox - Added `htmlIdGenerator` namespacing for clarity to all prefix/suffix sections - Fixed casing on `bothPrefixSuffix.js` to snake_casing (per rest of codebase) - Fixed casing of all source & snippet vars to camelCasing - Fixed `sufix` typo
Preview documentation changes for this PR: https://eui.elastic.co/pr_5133/ |
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!
Codesandbox links are working, except for the one with the new hook, which is to be expected before it's released.
Ahh phew, thanks a million Greg, I was worried I'd done something wrong there! 😅 Merging this in now! |
Yeah we currently don't have a method to use a pre-release EUI package in codesandbox, so it uses the latest release. So any new things components, services, or props in a PR are unavailable. |
Summary
@kqualters-elastic recently raised that our EuiDataGrid IDs were regenerating on every change/rerender (e.g. click/sort/paginate events, etc.). The way to fix this is to memoize the generated ID.
I opted to create a custom hook helper withuseRef
, as the generated ID isn't really meant to change unless the component fully unmounts/mounts, and I thinkuseRef
conveys that slightly more accurately than state.Per @chandlerprall's excellent breakdown and @breehall's work, I've determined that
useMemo
definitely beats outuseRef
in terms of usage and updated this PR accordingly!Before
(Note the yellow flash on the
id
props on change)After
Checklist
- [ ] Check against all themes for compatibility in both light and dark modes- [ ] Checked in mobile- [ ] Checked in Chrome, Safari, Edge, and Firefox- [ ] Props have proper autodocs and playground toggles- [ ] Checked for breaking changes and labeled appropriately