Skip to content

docs: keep dehydrated serializable on flight requests in the Next pages example - #251

Merged
dangreen merged 1 commit into
mainfrom
docs/next-pages-example-flight-dehydrated
Sep 8, 2026
Merged

dangreen merged 1 commit into
mainfrom
docs/next-pages-example-flight-dehydrated

Conversation

@dangreen

@dangreen dangreen commented Sep 8, 2026

Copy link
Copy Markdown
Member

Why

src/pages/characters.tsx in the Next pages example skips dehydration on flight requests:

let dehydrated

if (!isFlight(context.req.headers)) {
  dehydrated = await dehydrate(...)
}

return { props: { dehydrated } }

Next rejects an explicitly undefined prop returned from getServerSideProps in development (isSerializableProps, enabled under the dev server and build-time SSG). Reproduced with NANO_KIT_DEV=1 next dev --webpack and a real click on the CHARACTERS link from /episodes:

GET /_next/data/development/characters.json -> 500
GET /characters                             -> 200   (Next falls back to a full reload)

⨯ Error: Error serializing `.dehydrated` returned from `getServerSideProps` in "/characters".
Reason: `undefined` cannot be serialized as JSON. Please use `null` or omit this value.

Production is unaffected, since JSON.stringify drops the key, but the example demonstrates exactly the scenario that breaks in next dev.

What

The page is back to the single expression it had before 33b6e0b, which only switched to let because the navigation setup took two statements at the time:

const dehydrated = !isFlight(context.req.headers) && await dehydrate(
  Stores$,
  [
    provide(LocationNavigation$, virtualNavigation(context.resolvedUrl, routes))
  ]
)

A flight request now returns false, which Next serializes and HydrationProvider treats as "skip hydration".

Checks

  • Same click after the change: _next/data/development/characters.json answers 200, no document request follows, the console is clean.
  • oxlint on the file passes. The example's tsc reports only pre-existing noise from generated .next types and import.meta.env in the symlinked package sources.

…ages example

The characters page of the Next pages example skipped dehydration on flight requests by leaving `dehydrated` undefined, and Next rejects an explicitly undefined `getServerSideProps` prop in development: every client-side navigation to `/characters` answered the data request with a 500 and fell back to a full reload. The page is back to `!isFlight(...) && await dehydrate(...)`, the form it had before the navigation setup needed two statements, so a flight request returns `false`, which Next serializes and `HydrationProvider` treats as "skip hydration".
@codecov

codecov Bot commented Sep 8, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 83.33%. Comparing base (8794697) to head (9d67864).

Additional details and impacted files
@@            Coverage Diff             @@
##             main     #251      +/-   ##
==========================================
+ Coverage   83.29%   83.33%   +0.03%     
==========================================
  Files          98       98              
  Lines        2556     2556              
  Branches      551      551              
==========================================
+ Hits         2129     2130       +1     
  Misses        314      314              
+ Partials      113      112       -1     

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@dangreen
dangreen merged commit fb4365f into main Sep 8, 2026
10 checks passed
@dangreen
dangreen deleted the docs/next-pages-example-flight-dehydrated branch September 8, 2026 22:05
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant