MSD: Refactor interim omnibar to hooks-based data flow#109881
Open
StevenDufresne wants to merge 7 commits intotrunkfrom
Open
MSD: Refactor interim omnibar to hooks-based data flow#109881StevenDufresne wants to merge 7 commits intotrunkfrom
StevenDufresne wants to merge 7 commits intotrunkfrom
Conversation
The previous implementation drove React imperatively via `root.render` and `QueryObserver.subscribe` after `hydrateRoot`, which raced hydration and caused React to bail out with "This root received an early update, before anything was able to hydrate. Switched the entire root to client rendering." Move the data fetching into a new `InterimOmnibarContainer` that uses TanStack Query hooks (`useQuery` for auth, recentSites, and the active site). A `useState(false)` + `useEffect` gate ensures the first render mirrors the SSR output exactly (`user = initialUser`, `site = null`, no toggle callbacks); after hydration commits, the container switches to hook-driven data and wires up the toggle handlers. All post-hydration updates now flow through normal React rendering instead of external imperative calls. `loadOmnibar` shrinks to just click delegation and a single `hydrateRoot` call. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Jetpack Cloud Live (direct link)
Automattic for Agencies Live (direct link)
Dashboard Live (dotcom) (direct link)
|
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Contributor
|
This PR modifies the release build for the following Calypso Apps: For info about this notification, see here: PCYsg-OT6-p2
To test WordPress.com changes, run |
Extract the data-flow logic into an exported `useInterimOmnibarData` hook so it can be tested in isolation without rendering the full masterbar tree. Add unit tests covering: bootstrapped user via initialData, toggle callback wiring, recent-site loading, primary_blog fallback, and the null-site state when no siteId is known. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Replace the weak assertions (`initialData` pass-through and the `site === null` default) with a `renderToStaticMarkup`-based test that verifies the hook's pre-hydration output matches the SSR shape exactly (user, null site, no callbacks). This is the contract hydration actually depends on. Drop the "keeps site null" test — it only asserted a destructuring default and would have passed even if the enabled guard was removed. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Move the hook out of `interim-omnibar-container.tsx` into `use-interim-omnibar-data.ts`, matching the source-file naming convention used by `hooks/use-persistent-view.ts` (and lining up with the test file name). Tests now build a fresh `OmnibarEvents` per test instead of subscribing to the shared module singleton, so a failed assertion can't leak a dangling subscription into later tests. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
8 tasks
Comment on lines
+76
to
+78
| afterEach( () => { | ||
| nock.cleanAll(); | ||
| } ); |
Contributor
There was a problem hiding this comment.
This afterEach can be removed — nock.cleanAll() is already called globally after each test.
Note:
nock.cleanAll()is already called globally after each test, so you don't needafterEach( () => nock.cleanAll() )in your test files.
Suggested change
| afterEach( () => { | |
| nock.cleanAll(); | |
| } ); |
8 tasks
This reverts commit 84a0480.
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.
Proposed Changes
loadOmnibarto mount a hooks-based container (useInterimOmnibarData) instead of driving React imperatively withroot.renderandQueryObserver.subscribeafterhydrateRoot.primary_blogfallback.Why are these changes being made?
The previous implementation raced hydration and caused React to bail with:
With the refactor, every post-hydration update flows through normal React rendering — there is no external code path that can update the root between
hydrateRootand its commit.Testing Instructions
dashboard/omnibarfeature flag.Pre-merge Checklist