Skip to content

fix(preact): reuse the parent context by default in HydrationProvider, as React does - #249

Merged
dangreen merged 1 commit into
mainfrom
fix/preact-hydration-reuse-default
Sep 8, 2026
Merged

fix(preact): reuse the parent context by default in HydrationProvider, as React does#249
dangreen merged 1 commit into
mainfrom
fix/preact-hydration-reuse-default

Conversation

@dangreen

@dangreen dangreen commented Sep 8, 2026

Copy link
Copy Markdown
Member

Why

HydrationProvider in @nano_kit/react defaults reuse to true since d833400, where nested hydration boundaries were introduced: a nested provider pushes its dehydrated snapshot into the shared hydrator and renders its children in the parent context. The Preact port never got that change and left reuse undefined, so the same tree created an isolated child context in Preact. The docs mirrored the split: React said "true by default", Preact said "set to true if you want the hydration context to be shared".

What

  • packages/preact/src/hydration.tsx: reuse = true, and the prop JSDoc states the default.
  • preact.mdx: the reuse prop line now matches the React page.
  • Tests in hydration.spec.tsx compare useInjectionContext() inside and outside a nested provider: should reuse the parent hydration context by default (fails on main) and should create a child context when reuse is disabled.

Nothing in the repo nests HydrationProvider in Preact without an explicit reuse: preact-ssr and preact-router do not use it, and the Preact examples go through StaticHydrationProvider.

Checks

  • oxlint, tsc --noEmit, vitest run (11 tests) and size-limit in packages/preact pass; the size limits are unchanged (666 B gzip of 700 B, 574 B brotli of 600 B).

…r`, as React does

`@nano_kit/react` switched the `reuse` prop of `HydrationProvider` to `true` by default when nested hydration boundaries arrived, so a nested provider renders its children in the parent context. The Preact port kept `reuse` undefined, so the same tree created an isolated child context there, and the two adapters documented different defaults for the same prop. Preact now defaults to `true` as well; pass `reuse={false}` to keep a child context.
@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.29%. Comparing base (bae248e) to head (2a9586b).

Additional details and impacted files
@@            Coverage Diff             @@
##             main     #249      +/-   ##
==========================================
- Coverage   83.33%   83.29%   -0.04%     
==========================================
  Files          98       98              
  Lines        2556     2556              
  Branches      551      551              
==========================================
- Hits         2130     2129       -1     
  Misses        314      314              
- Partials      112      113       +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 cb2d9e2 into main Sep 8, 2026
9 of 10 checks passed
@dangreen
dangreen deleted the fix/preact-hydration-reuse-default branch September 8, 2026 16:35
@github-actions github-actions Bot mentioned this pull request Sep 8, 2026
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