Repository navigation
Server rendering and hydration (#66, Part 7) - #75
Merged
Merged
Conversation
…66, 7.1) Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…eme (#66, 7.2) Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…n the Next.js fixture (#66, 7.7) Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
76 tasks
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.
Fixes Part 7 of #66: server rendering and hydration. Every item has a test that failed first. 7.1 to 7.5 use a new
test/hydrate.tsxhelper (renderToString, then browser-only setup, thenhydrateRoot). 7.6 and 7.7 use thee2e/nextjsfixture.ThemeProviderreads the stored theme withuseSyncExternalStore(server snapshotnull, so it hydrates withdefaultThemeand then switches). It also follows thestorageevent (other tabs). If storage is blocked, a choice is kept in memory for the visit.ThemeToggle variant="segmented"now selects the stored theme after hydration.ui/sonner.tsxreadsuseTheme(), so this fixes it too.themeScripttakes the provider's options as an object,themeScript({ defaultTheme, forcedTheme, storageKey }). It appliesforcedTheme, and a stored value that isn't a theme falls back todefaultTheme, like the provider does.ShareButtonswithouturlreads the page URL withuseSyncExternalStore(server snapshot""), so the links get the URL after hydration instead of keeping stalehrefs.FullCalendarno longer seeds state fromuseIsMobile(). Until a view is picked, the view is derived (view ?? picked ?? defaultView ?? (isMobile ? "agenda" : "month")), so phones switch to the agenda after hydration.useToday(pinned?)hook:nullwhile server rendering and hydrating, the device's date after that.DateCalendarandHijriCalendarmark no day as today until it is known. HijriCalendar's roving focus target is now[focused, selected, today]with a fallback to the 1st."use client"only to modules whose source starts with the directive (a small Vite plugin plus abannerfunction). It is now on 286 of 396 output modules.themeScriptmoved toproviders/theme-script.ts. 13 modules that use hooks or context and had relied on the blanket banner now have the directive in source (icons/icon*,hooks/*,charts/format,files/file-utils,form/required-marker,layout/feature-grid, and theui/breadcrumb,ui/paginationandui/native-selectprimitives, which have// onu:notes). Newsrc/use-client.test.tskeeps it that way. The fixture's root layout callsthemeScript()and its page callscn,transliterate(/thaana) andtoCsv(/export), all in Server Components.e2e/nextjs/app/hydrationpage (segmentedThemeToggle,ShareButtonswithouturl,FullCalendar).ssr-check.mjsopens it at 375px withonu-theme=darkstored and checks the dark class, the selected toggle, the sharehrefanddata-view="agenda", in both locales.Skipped ([P] / device check)
Could not reproduce
Behaviour and API changes
themeScript(storageKey, defaultTheme)is nowthemeScript({ storageKey, defaultTheme, forcedTheme }).Theme,ResolvedThemeand the newThemeScriptOptionslive inproviders/theme-script.ts. They are still exported from the root, andThemeProviderPropsextendsThemeScriptOptions.ThemeProviderfollows theme changes made in other tabs.FullCalendarwith nodefaultViewfollows the screen width (agenda belowmd) until the user picks a view.todaymark no day as today until hydration. Passtodayto have it in the server HTML.defaultMonthortoday, the initial month still comes from the client clock while hydrating. On the 1st of a month between 00:00 and 05:00 MVT, a UTC server's month can differ. That is a text mismatch, which React recovers from by client-rendering. PassdefaultMonthortodayto avoid it.guides/dark-mode.md,guides/inertia-and-nextjs.md(theThemeScriptclient wrapper is gone),share-buttons.md,full-calendar.md,date-calendar.md,hijri-date-picker.md, andCONTRIBUTING.md(a rule for adding"use client").Verification
pnpm lint && pnpm format:check && pnpm typecheck: passpnpm --filter @javaabu/onu exec vitest run --maxWorkers=3: 198 files, 2869 passed, 1 skippednode scripts/check-docs.mjs: Docs OK.node scripts/boost.mjs --check: OKpnpm build && pnpm --filter @javaabu/onu size: pass, no budget changespnpm --filter onu-nextjs-fixture build && pnpm --filter onu-nextjs-fixture test:ssr: both locales pass (11 HTML strings, clean hydration, browser-only state applied)Attempted to call cn() from the server but cn is on the client(and the same forthemeScript).ShareButtons, the oldFullCalendarand aThemeProviderthat reads storage while hydrating.test:ssrthen reported all three problems in both locales.🤖 Generated with Claude Code