Mantle Alert Center Server Render Migration Guide
AlertCenter.Item used to render nothing until hydration, so its children never ran on the server, and the bar entered after hydration and pushed the page down. Now each item renders its children in a copy of the bar during the server render and the hydration pass, and the server HTML shows the top item. At hydration the client bar replaces the copy at the same height, so the page does not shift.
TL;DR: Prefetch the data your alert items read in the root loader, so the items exist during the server render. Then find each item whose children read browser-only state during render, and each item that only the browser can decide (such as one hidden by a dismissal in sessionStorage). Render those only after useIsHydrated() returns true.
Codemod
Codemod: manual: which children read browser-only state, and which items depend on browser storage, is a semantic question that no syntax rule can answer.
You are an agent migrating a codebase. Do this:
- Find every
AlertCenter.Item, including items authored inside your own components, and the code that decides whether each one mounts. - If that decision reads
sessionStorage,localStorage, or any state that the server cannot read (such as a dismissed set fromuseSessionStorage), render the item only afteruseIsHydrated()from@ngrok/mantle/hooksreturnstrue. Items that the server can decide, such as an alert the user cannot dismiss, need no gate. - If an item's children read
window,document,localStorage, the current time, or another browser-only value during render, move that read into an effect, or gate the child withuseIsHydrated(). - In your root loader, prefetch the data your items read, such as your notifications or account notices query, and seed your data cache with it. Without it, the server has no items, and the bar still enters after hydration.
- Keep the items after
AlertCenter.Barin the same parent, and compose oneAlertCenter.Rootfor each parent. - After editing, run the project's formatter, linter, type checker, and tests.
Why render on the server? A bar that appears after hydration pushes the whole app down, which counts toward Cumulative Layout Shift. A copy of the bar in the server HTML takes its place from the first paint.
Before → after
An item hidden by a dismissal in sessionStorage
A child that reads the window during render
Edge cases & gotchas
- Items that already render only after hydration change nothing. They enter after hydration, as before.
- At hydration the item's children mount again in the bar, so their mount effects run twice in production.
AlertCenter.BarandAlertCenter.Contentnow render a hidden anchor while they show nothing, so a test that expects an empty notice slot must ignore hidden elements.- An item authored away from the bar keeps a hidden copy and enters after hydration. With
defaultOpen, the expansion rows also enter after hydration.
How to verify
Render a page with an active alert on the server, and read the HTML: it holds an element with data-slot="alert-center-server-bar" and the alert's title. Load the page with hydration slowed down, and check that the page does not move when hydration runs.