Repository navigation
fix(AppShell): with the standard width points, a server-rendered shell hides its inline side nav on a phone before its script runs - #12396
josephfarina wants to merge 3 commits into
Conversation
… its script runs Below the breakpoint, the server HTML showed the inline side nav until hydration read the window, so phones saw the navigation for a moment and then saw it disappear. Until the shell reads the window, it now adds a media-query rule with the resolved breakpoint width that hides the inline side region and flattens the elevated corner.
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
|
AI review status for this pull request.
|
There was a problem hiding this comment.
Requesting changes: the first-paint fix works for the side nav, but three things need to change first.
AppShell.tsxlines 138-142 and 651-655 re-implement the shareduseIsHydratinghook, so useconst hasReadWindow = !useIsHydrating();asMobileNavdoes and delete the local helpers.- The changeset and the title say the first paint already uses the phone layout, but the top nav keeps its full mode, items and no toggle, and a sidenav-only shell has no top bar until the script runs, so reword both (and the comment at
AppShell.tsx:879) to say the side nav is hidden and the menu toggle still arrives with the script. appShellUnread.stylex.tswrites its selectors in an injected<style>rule on elements Core renders, whicharchitecture:public-component-apiINV23 allows only for an attribute on an element the package does not render, so either an engineering owner amends INV23 for a rule whose media width comes from the theme, or the rule moves intostylex.create.
The red-first tests and the 390 px first-paint frames confirm the side-panel fix, and widths at or above the breakpoint paint exactly as before. CI's test and build jobs did not run on this head because the CI queue was full, so they still need a run.
Claims and files checked
Review mode: full; reason: no-earlier-review
- Claim: on a phone the server-rendered page no longer shows the side nav while its script loads: verified (new tests fail on the base and pass on the head; 390 px first-paint frames).
- Claim: the first paint already uses the phone layout: false (the top nav stays in full mode with no toggle; a sidenav-only shell gains its top bar only at hydration).
- Claim: a Core patch with no new prop, export or default: verified (the API report lists no change).
- Claim: without the SSR hint the server HTML was always the wide layout: verified (base frames and code).
- Claim: the rule uses the breakpoint's resolved width, so a theme override is respected: verified (theme test with an
lgoverride). - Claim: below that width the rule hides the side region and flattens the elevated corner: verified (server-HTML test, head frame).
- Claim: once the shell reads the window it drops the marks and renders the layout as before: verified (hydration tests on both sides of the breakpoint).
- Claim: the owner module writes its rule the way the scroll-anchoring owner does, within INV23: false (that owner marks caller-owned scroll containers; INV23's injected-rule exception covers only those).
- Claim: the hydration read is deferred with the breakpoint answer, so the hydration-safe switch is unchanged: verified in code (it duplicates the shared hook).
- Claim: a client render, the SSR hint, breakpoint none, or no side nav adds nothing: verified (tests).
- Claim: React hoists one style per width into the head: verified (server render probe).
- Claim: the menu toggle still arrives when the script runs: verified.
- Claim: four of the eight new tests fail on main: verified (red-first run).
- Claim: the type check is clean: verified (Core type check passes); the full UI suite was not rerun (the AppShell suites pass).
- Claim (title): the shell paints the phone layout before its script runs: false (same as above).
- File
.changeset/appshell-phone-first-paint.md: finding (wording). - File
packages/core/src/AppShell/AppShell.tsx: finding (duplicate hydration read; comment wording). - File
packages/core/src/AppShell/AppShell.test.tsx: clear. - File
packages/core/src/privateAttributes/appShellUnread.stylex.ts: finding (injected rule under INV23).
PR Analysis Report🔎 Preview ·
|
Review changes: the shell reads useIsHydrating instead of its own store; the rule is one StyleX media-query style per standard width point on the inline side region and the elevated backdrop, so no private attribute or injected style; a theme that moves the point keeps the server layout until hydration. The touch presentation guard takes the standard width points as reference spellings. The changeset says the side nav is hidden and the toggle still arrives with the script.
There was a problem hiding this comment.
Requesting changes: the side-nav first-paint fix works, and the three points from the last review are fixed, but the release note promises more than the code does.
.changeset/appshell-phone-first-paint.md(and the title and thedefaultIsMobileJSDoc inAppShell.tsx) say every phone stops showing the side nav before the script runs, but the rule is added only for the standard width points, and the new testadds no rule for a theme that moves the width pointshows that a theme that moves the point still paints the side panel, so add that condition (for example "when the theme keeps the standard width points") to all three.
Two smaller suggestions: move the hydration test's appendChild and first assertion inside its try, so a failure does not leave the host in the page for later tests, and allow the width-point spellings in the touch-presentation guard only for AppShell.tsx. CI was still running on this head when this review was written.
Claims and files checked
Review mode: incremental; reason: none
- changed rules (0): none
- Changeset: on a phone, a server-rendered page no longer shows the inline side nav while its script loads: false for a theme that moves the width point (the rule is skipped there, and the new theme test proves it); verified for the standard points (new tests and 390 px first-paint frames).
- Changeset: the menu toggle still arrives with the script: verified (no toggle in the server HTML; one after hydration).
- Title: the shell hides its inline side nav on a phone before its script runs: false for a theme that moves the width point, as above.
- Phone visitors saw the side nav fill most of the screen until hydration, and desktop widths were unaffected: verified (base frame at 390 px: a 260 px panel and a 98 px content column; 1280 px frames identical on both trees).
- Without the SSR hint the server HTML is always the wide layout: verified (code and base frames).
- The side region takes 260 of 390 px and the page reflows at the switch: verified (content goes from 98 px to 358 px at hydration on the base).
- The User-Agent hint guesses wrong for narrow desktop windows and tablets: not checked (a judgement outside the code).
- Until the shell reads the window, the side region and the elevated backdrop carry one StyleX style under the selected point's media query: verified (code and server-HTML tests).
- Below that width the side region does not paint and the backdrop loses its corner: verified (probe: display none and a 0px corner at 390 px).
- Once the shell reads the window it drops the styles and renders the layout as before: verified (hydration tests on both sides of the breakpoint).
- The top nav keeps its full mode and the toggle arrives with the script: verified (head frames).
- The shell reads the shared hydration hook and defers it with the breakpoint answer: verified in code.
- One style per standard point; a client render, the SSR hint, breakpoint none, no side nav, or a theme that moves the point gets nothing: verified (tests and code).
- The touch guard takes the standard width points as reference spellings: verified; it now accepts them in every Core file (non-blocking note).
- No new prop, export, default, attribute or visual: verified (the API report lists no change; no data attribute is added).
- After the change the first frame has no side nav and full-width content, and 1280 px is unchanged: verified (first-paint frames; the 1280 px pair is pixel-identical).
- Four of the eight new tests fail on main: verified (red-first run).
- The type check and lint are clean: verified (Core type check passes; the Lint workflow passed on this head); the full UI suite, the knowledge check and the pre-review script were not rerun.
- Scope checklist (one defect restored, no tagalongs, no API under the fix label, no internal context in public text): verified (one primary delta, no API change, and a scan of the added lines, title, body and commit messages found no internal context).
- The production Next.js reproduction and its timings: not reproduced; a fixture that paints the server HTML without hydration shows the same first paint.
- File
.changeset/appshell-phone-first-paint.md: finding (scope wording). - File
packages/core/src/AppShell/AppShell.tsx: finding (thedefaultIsMobileJSDoc carries the same wording); the code is clear. - File
packages/core/src/AppShell/AppShell.test.tsx: non-blocking note (host left in the page when the hydration test fails). - File
packages/core/src/utils/touchPresentation.test.ts: non-blocking note (guard allowance is tree-wide).
The width-point styles use `not all and (min-width: N)`. StyleX lowers `(width < N)` to `(max-width: N - 0.01)`, which Chromium rounds up to N, so the side nav was hidden at exactly the breakpoint until hydration (caught by the docsite 768 px hydration test). Review: the changeset, title and `defaultIsMobile` doc name the standard width points as the condition; the hydration test attaches its host inside the try; the touch presentation guard accepts the width-point spellings only in AppShell.tsx.
There was a problem hiding this comment.
Approved pending CI: the server-rendered shell now keeps the inline side nav off a phone's first paint and keeps exactly the width point on the wide side, and every point from the last review is fixed.
CI did not run on this head because the run found no room under the CI ceiling, so re-run the CI jobs; the merge guard needs them green before merge. One optional suggestion is inline: split the new comment in AppShell.tsx into short one-topic sentences.
Claims and files checked
Review mode: incremental; reason: none
- changed rules (0): none
- Changeset: on a phone, with the standard width points, a server-rendered page no longer shows the inline side nav while its script loads: verified (new tests; 390 px and 767 px first-paint frames; the theme test bounds the condition).
- Changeset: the menu toggle still arrives with the script: verified (no toggle in the first paint; one after the client render).
- Title: with the standard width points, the shell hides its inline side nav on a phone before its script runs: verified, as above.
- Phone visitors saw the side nav fill most of the screen until hydration, and desktop widths were unaffected: verified (base frame at 390 px: a 260 px panel and a 98 px content column; 1280 px frames identical on both trees).
- Without the SSR hint the server HTML is the wide layout: verified (code).
- The side region takes 260 of 390 px and the page reflows at the switch: verified (content goes from 98 px to 358 px after the client render).
- The User-Agent hint guesses wrong for narrow desktop windows and tablets: not checked (a judgement outside the code).
- Until the shell reads the window, the side region and the elevated backdrop carry one StyleX style under the selected point's media query: verified (code and server-HTML tests).
- Below that width the side region does not paint and the backdrop loses its corner: verified (probe: panel hidden at 390 px and 767 px; flat content corner in the frame).
- Once the shell reads the window it drops the styles and renders the layout as before: verified (hydration tests on both sides of the breakpoint).
- The top nav keeps its full mode and the toggle arrives with the script: verified (head frames).
- The shell reads the shared hydration hook and defers it with the breakpoint answer: verified in code.
- One style per standard width point, because StyleX compiles media queries ahead of time: verified in code.
- The queries use
not all and (min-width: N)because StyleX lowers(width < N)to(max-width: N - 0.01px), which Chromium matches at N: verified (the StyleX plugin's lowering; a Chromium probe at exactly 768 px matches the lowered query and not the new one; the built CSS keeps the new spelling). - The docsite's 768 px hydration test caught that edge: verified (it failed on the previous head, the first head where that job ran).
- Only a shell whose first render is the wide layout with an inline side nav at a standard point gets the style; a client render, the SSR hint,
none, no side nav, or a moved point gets nothing: verified (code and tests). - The touch guard accepts the width-point spellings only in
AppShell.tsx: verified (code; the guard still flags themdspelling in any other file). - No new prop, export, default, attribute or visual: verified (the API report lists no change; no data attribute is added).
- After the change the first frame has no side nav and full-width content, and the menu button arrives at hydration: verified (first-paint and client-render frames).
- At 1280 px and at exactly 768 px the inline side nav shows from the first frame, and at 767 px it is hidden: verified (768 px and 1280 px frames identical to the base; panel hidden at 767 px).
- Four of the eight new tests fail on main: verified (red-first run: 4 fail, 4 pass, no other test affected).
- The production Next.js reproduction and its timings: not reproduced; a fixture that paints the server HTML without hydration shows the same first paint.
- The type check and lint are clean: verified (Core type check passes; the Lint workflow passed on this head); the full UI suite, the knowledge check and the pre-review script were not rerun.
- Scope checklist (one defect restored, no tagalongs, no API under the fix label, no internal context in public text): verified (one primary delta, no API change, and a scan of the added lines, title, body and commit messages found no internal context).
- File
.changeset/appshell-phone-first-paint.md: clear. - File
packages/core/src/AppShell/AppShell.tsx: clear (one non-blocking comment-style suggestion). - File
packages/core/src/AppShell/AppShell.test.tsx: clear. - File
packages/core/src/utils/touchPresentation.test.ts: clear.
| // layout. The queries use `not all and (min-width)`: StyleX lowers | ||
| // `(width < N)` to `(max-width: N - 0.01)`, which Chromium rounds up to N, so | ||
| // the rule would also apply at the point itself. |
There was a problem hiding this comment.
Non-blocking: this keeps a real reason, but packs the choice, StyleX's lowering, Chromium's match and the consequence into one conditional sentence of about 30 words. A one-topic-per-sentence version:
// StyleX lowers `(width < N)` to `(max-width: N - 0.01px)`. Chromium matches
// that query at width N too. `not all and (min-width: N)` keeps N on the wide
// side.…rendered shell hides its inline side nav on a phone before its script runs
…rendered shell hides its inline side nav on a phone before its script runs
- #12252 docs(cli): agent docs name the prop names that differ from other libraries Author: Joey Farina <[email protected]> - #12154 fix(core): a numeric typography weight builds through an extended base's adaptation rules Author: Joey <[email protected]> - #12092 fix(cli): theme build reads the Core it builds with for variant declarations, and names the build command alone Author: Joey Farina <[email protected]> - #12316 fix(core): a shorthand never follows its own longhand in one style merge Author: josephfarina <[email protected]> - #12357 fix(core): a Table stays the scroll region when a host scrolls every table's parent Author: Joey Farina <[email protected]> - #12349 fix(core): end a mouse drag a sandboxed frame never saw released Author: josephfarina <[email protected]> - #12425 fix(cli): use a stored doc parse only with the zod release that made it Author: Joey <[email protected]> - #12396 fix(AppShell): with the standard width points, a server-rendered shell hides its inline side nav on a phone before its script runs Author: Joey <[email protected]> - #12438 fix(charts): end dots draw whole and a thinned axis keeps its last label Author: Joey Farina <[email protected]> - #12448 fix(cli): upgrade outside a project names the project, not --from Author: Joey Farina <[email protected]> - #12459 fix(templates): the dashboard scorecard fits a phone screen Author: Joey Farina <[email protected]> - #12428 fix(core): Field labels draw in a bolder face than their description Author: Joey Farina <[email protected]> - #12435 fix(theme-matcha): dark menus, popovers and muted fills take the theme's deep gray neutral Author: Joey <[email protected]> - #12432 fix(templates): dashboard chart labels show whole instead of clipped by the chart edge Author: Joey Farina <[email protected]> - #12441 fix(cli): mark icon-set generated calls pure so apps drop unused icons Author: Joey Farina <[email protected]> - #12472 fix(MetadataListItem): a value breaks only a word longer than its line Author: Joey <[email protected]>
|
Landed in #12718. |
User impact
People who open a server-rendered app built on
AppShellwith a side nav on a phone (with a theme that keeps the standard width points) saw the side navigation fill most of the screen for a moment, then disappear when the page's script ran. On a slow connection the moment lasts seconds, and it reads as a menu that opens and closes by itself. Desktop widths were not affected.Problem and solution fit
AppShelldecides between the wide and the phone layout with a media query hook. The server cannot read the window, so the server HTML is always the wide layout (unless the caller passes thedefaultIsMobilehint from the User-Agent). The inline side region stays in the page until hydration reads the window.The breakpoint is a responsive condition that CSS can resolve before any script runs (
architecture:component-style-authoringINV2). Until the shell reads the window, the inline side region and the elevated backdrop carry one StyleX style under the selected width point's media query. Below that width, the side region does not paint and the backdrop loses its corner, as in the phone layout. When the shell reads the window, it drops the styles and renders the layoutcomponent:AppShellFR8 selects, as before. The top nav keeps its full mode and the menu toggle still arrives with the script.Expected behavior and authority
component:AppShellFR8 and FR9: below the breakpoint, the side nav leaves the inline region.architecture:component-style-authoringINV2: CSS owns a responsive condition it can derive.Smallest restoration
AppShellreadsuseIsHydratingand defers it together with the breakpoint answer, so the existing hydration-safe transition (content that has not hydrated keeps its server HTML) is unchanged.not all and (min-width: N): StyleX lowers(width < N)to(max-width: N - 0.01px), which Chromium rounds up to N, so the rule would also hide the side nav at exactly the breakpoint (the docsite's 768 px hydration test caught this on the first push). Only a shell whose first render is the wide layout with an inline side nav and a standard width point gets it. A client render,defaultIsMobile,breakpoint: 'none', no side nav, or a theme that moves the width point gets nothing and keeps today's behavior.AppShell.tsx(width-only queries, not the compact size).Evidence
AppShell variant="elevated", a TopNav and a SideNav, at 390 px with slow scripts. The side nav is visible at 260 px wide from the first frame until hydration (2.6 s), then it disappears.AppShell.test.tsx"first paint before the shell reads the window" checks the styles in the server HTML formdandlg, the cases that add nothing (SSR hint,none, a theme that moves the point, a client render), and hydration on both sides of the breakpoint. Four of the eight tests fail onmain.Scope
Components: AppShell
Testing
CI=1 vitest run --project ui packages/core: 23,752 of 23,753 pass; the one failure is a 30 s timeout insemanticFence.shared.test.tsxunder full-suite load, which passes on its own.tsc --noEmit -p packages/core/tsconfig.json,eslinton the changed files,pnpm check:knowledge, andpnpm review:preare clean.next build && next startwith this branch's packed@astryxdesign/coreand withmain's.