Skip to content

fix: avoid creating requests for server-seeded hydration data - #683

Merged
trueadm merged 1 commit into
octanejs:mainfrom
openai-oss-forks:fix/673-hydration-seed-request-creation
Aug 10, 2026
Merged

trueadm merged 1 commit into
octanejs:mainfrom
openai-oss-forks:fix/673-hydration-seed-request-creation

Conversation

@domgan-oai

@domgan-oai domgan-oai commented Aug 10, 2026 •

Copy link
Copy Markdown
Contributor

Summary

  • Consult server-provided hydration seeds before invoking eligible compiler-owned use(factory(...)) request creators.
  • Preserve fulfilled and rejected values, existing promise ownership, repeated request sites, streamed boundaries, deferred hydration, and subsequent dependency changes.
  • Add a patch changeset and document the hydration behavior.

Part of #673.

Why

Previously, hydration adopted the server result only after evaluating the client-side request factory. That started a duplicate request even though its result was immediately discarded. Independent request creation can also move ahead of use() consumption, so a positional seed lookup alone can incorrectly claim a context, externally owned promise, or another component occurrence.

Changes

  • Give eligible direct request sites the same source-derived identity in server and client compiler output.
  • Record actual server-owned seed outcomes and skipped context/external outcomes per occurrence; extend the existing rejection envelope only when ownership metadata is necessary.
  • Defer client request creation until the matching site outcome is known, consume seeds in their original use() order, and retain normal request creation when metadata is missing or invalid.
  • Keep seed ownership attached to existing root, streamed, nested, and deferred hydration scopes without changing the legacy wire format for unrelated promises.
  • Move adoption behind the hydration capability so client-only bundles tree-shake the new protocol.

Validation

  • pnpm format:check
  • pnpm --config.enable-pre-post-scripts=false run typecheck — full workspace typecheck body, including bindings, core typetests, integrations, website, 17 example apps, and benchmarks. The unrelated Solana pretypecheck was disabled because its dependencies are unavailable in the cached worktree installation.
  • pnpm exec vitest run --project octane --project octane-prod --silent=passed-only — 804 files, 11,657 tests passed.
  • pnpm exec vitest run packages/octane/tests/browser/suspense-hydration/suspense-hydration.test.ts --project octane-events-browser --silent=passed-only — 11 real-browser streamed hydration tests passed.
  • ./node_modules/.bin/vitest run packages/octane/tests/hydration/suspense-hydrate.test.ts --project octane --project octane-prod --silent=passed-only — fulfilled/rejected seeds, zero request creation, independent sites, existing promises, contexts, external owners, repeated sites, streamed nesting, deferred activation, and dependency invalidation.
  • node benchmarks/bench.mjs --quick async-composition — production browser workload preserved 2 request waves, 8 actual requests per operation, and zero mixed states.
  • node benchmarks/bundle-size/run-minimal.mjs — all production reachability scenarios execute successfully; client-only static/suspense entries shrink against the same-commit baseline.
  • node benchmarks/codegen-size/run.mjs — fixed corpus remains 152,623 raw / 75,339 minified bytes.
  • pnpm changeset:check
  • pnpm sync
  • pnpm test — full cross-workspace project matrix was not run; the complete Octane development/production matrix and browser hydration project were run instead.

Risk / follow-ups

  • The optimization intentionally applies only to compiler-owned direct call/new factories; existing promises, optional/conditional expressions, creation chains, custom renderer output, and unrecognized ownership retain their previous behavior.
  • Hydration-enabled bundles grow approximately 0.55–0.58 KiB gzip for the ownership protocol; ordinary client-only entries shrink approximately 50–70 bytes gzip. Server-render grows 187 bytes gzip and lands 84 raw bytes above its existing 31,600-byte raw budget; its gzip/brotli budgets remain satisfied. Separate deferred-hydration and suspense raw budgets already fail on untouched canonical main.

Provenance

  • An agent produced this diff (agent-authored)

Note

Medium Risk
Touches SSR seed serialization, client hydration use() ordering, and compiler codegen for direct async creations; behavior is narrowed to compiler-owned sites but wire-format and hydration edge cases are easy to get wrong.

Overview
Fixes hydration starting duplicate client requests when the server already resolved the same compiler-owned use(call/new) site—the factory used to run before the seed was consumed.

The compiler assigns a stable hydration site id to eligible direct creations and wraps client memo callbacks in seedOrCreate, which returns a lazy thenable tied to that site instead of invoking the factory immediately. Server use() records fulfilled/rejected outcomes (or “skipped” markers for context, external owners, and non-owned thenables) into the suspense seed wire format via optional sites metadata on the existing rejection envelope; empty seed arrays no longer emit seed <script> tags.

Client hydration decodes site queues, seedOrCreate consults them before running factories, and useSeed keeps positional seed consumption aligned with ordinary use() order—including nested stream, deferred Hydrate, and post-hydration prop updates that should refetch.

Reviewed by Cursor Bugbot for commit c14b5e1. Bugbot is set up for automated code reviews on this repo. Configure here.

@github-actions github-actions Bot added agent-authored Diff or issue body substantially produced by an AI agent fix PR: bug fix labels Aug 10, 2026
@domgan-oai
domgan-oai marked this pull request as ready for review August 10, 2026 11:11
@trueadm
trueadm merged commit 4cc7840 into octanejs:main Aug 10, 2026
53 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

agent-authored Diff or issue body substantially produced by an AI agent fix PR: bug fix

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants