Skip to content

Client-only createRoot bundles retain HTML hydration normalization #1785

Closed

Description

@domgan-oai

Description

A bundle that exports only createRoot retains HTML normalization used by setHTML's hydration-adoption branch, even though that bundle does not include hydrateRoot or the HydrationCapability class. This adds avoidable work to the client-only renderer graph.

Reproduction

With Node 26.4.0, install [email protected] and [email protected], then run this as an .mjs file from the package directory:

import { build } from 'esbuild';
import { gzipSync } from 'node:zlib';

const result = await build({
  stdin: {
    contents: "export { createRoot } from 'octane';",
    resolveDir: process.cwd(),
    sourcefile: 'probe-entry.ts',
  },
  bundle: true,
  write: false,
  format: 'esm',
  platform: 'browser',
  target: 'es2022',
  minify: true,
  treeShaking: true,
  define: {
    __OCTANE_PROFILE_ENABLED__: 'false',
    'process.env.NODE_ENV': '"production"',
  },
});
const bytes = result.outputFiles[0].contents;
console.log({ minified: bytes.length, gzip: gzipSync(bytes, { level: 9 }).length });

The published package produced 199,687 minified bytes and 63,906 gzip bytes in this probe. setHTML still reaches the hydration-only HTML/script normalization branch via activeHydration(), despite the capability constructor being absent from the closed bundle.

Possible direction

An experimental extraction of that adoption branch into a HydrationCapability method, following the approach in #1637, produced 198,970 minified bytes and 63,662 gzip bytes in the same root-only probe. The hydrateRoot-only bundle increased by 59 minified / 38 gzip bytes. Basic client mount/update and server-node adoption controls passed, but this is only a proof of direction: mixed roots, deferred hydration, script behavior, rollback, and split-chunk cases still need regression coverage before adopting a change.

The larger hydrateRoot graph remains necessary for applications that actually hydrate; this report is specifically about client-only bundles.

Follow-up on an extraction prototype

Against main 3754039d, with Node 24.19.0, Vite 8.1.5, and esbuild 0.28.1, moving the branch into the existing hydration capability reduced the reusable client-root esbuild fixture from 202,644 to 201,943 minified bytes (65,087 to 64,839 gzip). However, the Vite hydration-only fixture increased from 175,021 to 175,795 minified bytes (55,506 to 55,768 gzip), exceeding its existing size budget. The extraction retains normalization for hydration bundles that do not use raw HTML, so it is not a complete fix.

Focused hydration and script-normalization tests passed in development and production, but they do not resolve that size tradeoff. The hydration rewrite in #1784 is also changing this path; any candidate should be remeasured and validated against its eventual implementation.

Activity

  1. o-alexandrov commented on Oct 6, 2026

    @o-alexandrov
    Contributor

    Measured the proposed extraction on main (8aeb6c0e5) with the repository's own gate, benchmarks/bundle-size/run-minimal.mjs (Vite 8 scenarios), before deciding whether to open a PR. Part of #1801.

    scenario main raw / gzip adoption branch as a HydrationCapability method only the normalization as a method
    root-static (createRoot) 205,784 / 65,597 205,079 / 65,348 (−249 gz) 205,284 / 65,395 (−202 gz)
    hydrate-root 171,016 / 54,245 171,788 / 54,514 (+269 gz) 171,561 / 54,456 (+211 gz)
    deferred-hydration 234,692 / 74,245 235,464 / 74,495 (+250 gz) 235,237 / 74,455 (+210 gz)

    Why: hydrate-root and deferred-hydration do not use dangerouslySetInnerHTML, so on main setHTML and the normalization helpers are shaken out of them. As a class method the helpers become reachable from HydrationCapability itself, so every hydrating bundle pays them whether or not it uses raw HTML. The esbuild probe in the description (+38 gz for hydrateRoot) understates this under Vite/oxc.

    So this moves bytes from client-only apps that use raw HTML to every hydrating app, and it would raise two committed budgets. I'm not opening a PR for it. A fix that saves bytes in both directions needs the branch to be reachable only when both hydration and setHTML are in the graph, for example a compiler-emitted hydration variant of the raw-HTML write, rather than a capability method.

    The regression test I wrote for the adoption path (equivalent spelling <b >same</b > adopts the server node without a warning, then updates apply) is still useful for whoever takes this; it fails when normalization or the DANGER_HTML_VALUE bookkeeping is skipped.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions