Conversation
Keep the server snapshot until the client portal commits to avoid removing and recreating server-rendered items. Rebuild the client collection without stale server keys so clearing or replacing items on mount updates its size and contents consistently.
There was a problem hiding this comment.
Copilot review overview
🟢 Approval recommended
No unresolved review comments were identified, and regression coverage was added.
Review effort: Lite
Findings: None
What changed in this PR
Preserves server-rendered collection snapshots during hydration and applies client updates after portal commitment.
Changes:
- Defers collection updates during hydration.
- Finalizes pending updates after client portal commit.
- Adds SSR coverage for collection changes and DOM node reuse.
| File | Description |
|---|---|
packages/react-aria/src/collections/Document.ts |
Manages hydration snapshots and deferred updates. |
packages/react-aria/src/collections/CollectionBuilder.tsx |
Completes the SSR transition in a layout effect. |
packages/react-aria-components/test/Collection.ssr.test.js |
Tests collection updates and iteration state. |
packages/react-aria-components/test/Breadcrumbs.ssr.test.js |
Verifies server-rendered DOM node reuse. |
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
Author
|
Forgot to sign Adobe CLA |
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.
Hello, thank you very much for your effort. I like React Aria vey much.
I first encountered the issue while integrating React Aria into a Next.js project. The Breadcrumbs component appears, disappears, and then reappears.
Summary
Intent
Preserve server-rendered collection items during hydration instead of unnecessarily removing and recreating their DOM nodes. Collection changes made by the first client effects should also be reflected correctly, including when items are removed or replaced.
Root cause
During SSR,
Document.collectionandDocument.nextCollectionreference the same collection object. When switching to client rendering,resetAfterSSR()clears the document’s child pointers before React has committed the client portal.React’s
useSyncExternalStoremay read the snapshot again during this transition. Previously, that read could callupdateCollection()and commitnullas the first and last keys into the already-published collection. Its iterator would then return no items even though its key map and size still contained the server-rendered entries.In
Breadcrumbs, this caused React to remove the existing items and recreate them once the client collection was populated. Checking text content alone did not catch the problem because the final HTML could look unchanged.Implementation
The fix addresses the shared collection lifecycle rather than adding a workaround to
Breadcrumbs:isHydratingstate to preserve the existing snapshot and defer collection updates and notifications while the client portal is being prepared.finishSSR()from a layout effect inCollectionRootafter the client portal commits, allowing pending changes to be processed.BreadcrumbsSSR test to verify DOM node identity, and add collection-level coverage for initial effect updates and subsequent collection changes.AI assistance: GitHub Copilot assisted with root-cause investigation, regression-test refinement, and drafting this description.
✅ Pull Request Checklist:
📝 Test Instructions:
yarn test:ssr. Without the fixBreadcrumbs.ssr.test.jsandCollection.ssr.test.jsfail.BreadcrumbsSSR scenario preserves the originallistitemDOM nodes after hydration.useEffectanduseLayoutEffectcorrectly handle clearing, replacing, and populating items. Collection size, keys, and iteration order should remain consistent after subsequent restore/reorder and clear actions.