fix(preact): reuse the parent context by default in HydrationProvider, as React does - #249
Merged
Merged
Conversation
…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 Report✅ All modified and coverable lines are covered by tests. 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. 🚀 New features to boost your workflow:
|
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.
Why
HydrationProviderin@nano_kit/reactdefaultsreusetotruesince d833400, where nested hydration boundaries were introduced: a nested provider pushes itsdehydratedsnapshot into the shared hydrator and renders its children in the parent context. The Preact port never got that change and leftreuseundefined, so the same tree created an isolated child context in Preact. The docs mirrored the split: React said "trueby default", Preact said "set totrueif 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: thereuseprop line now matches the React page.hydration.spec.tsxcompareuseInjectionContext()inside and outside a nested provider:should reuse the parent hydration context by default(fails onmain) andshould create a child context when reuse is disabled.Nothing in the repo nests
HydrationProviderin Preact without an explicitreuse:preact-ssrandpreact-routerdo not use it, and the Preact examples go throughStaticHydrationProvider.Checks
oxlint,tsc --noEmit,vitest run(11 tests) andsize-limitinpackages/preactpass; the size limits are unchanged (666 B gzip of 700 B, 574 B brotli of 600 B).