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! |
cchaos
left a comment
There was a problem hiding this comment.
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
|
Preview documentation changes for this PR: https://eui.elastic.co/pr_5133/ |
Co-authored-by: Caroline Horn <549577+cchaos@users.noreply.github.com>
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/ |
thompsongl
left a comment
There was a problem hiding this comment.
Love how simple this hook turned out to be!
cchaos
left a comment
There was a problem hiding this comment.
👍 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/ |
thompsongl
left a comment
There was a problem hiding this comment.
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 thinkuseRefconveys that slightly more accurately than state.Per @chandlerprall's excellent breakdown and @breehall's work, I've determined that
useMemodefinitely beats outuseRefin terms of usage and updated this PR accordingly!Before
(Note the yellow flash on the
idprops 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