Skip to content

Reconcile whitespace where request-time instances meet - #149

Closed
collin-thomas wants to merge 1 commit into
mainfrom
fix/request-render-leading-comment
Closed

collin-thomas wants to merge 1 commit into
mainfrom
fix/request-render-leading-comment

Conversation

@collin-thomas

Copy link
Copy Markdown
Collaborator

Follow-up to the fidelity failure on #148. Independent of that PR; based on main.

What was wrong

With minify.html on, each component instance rendered from a server or stream script is minified on its own, while the build minifies the page once. Where two instances were written with nothing between them, the request-time bytes could differ from the build's:

  • In a table, a removed comment leaves an empty <!----> separator. The space between two inline instances landed before the separator (</a> <!----> <a>) where the build puts it after (</a><!----> <a>).
  • An instance that leaves nothing at its edge (empty, or only comments and whitespace) was treated as its neighbor's neighbor, so the instance beside it kept a space the build drops, or two spaces where the build keeps one.

These are byte differences. A browser renders both forms the same.

What it was not

A comment at the top of a component file does not reach this code in a real build: component files are minified as they are loaded, so the comment is already gone. The fidelity test hit it because it loaded each root's components once (with minify.html off for the first root) and reused that list for variants that build with it on.

Changes

  • request-render.ts: the usage finalizer resolves each instance's neighbors past instances that leave nothing, then merges the whitespace and separators at each seam the way the build treats that stretch. One pass over the pieces' edges.
  • component-manifest-fidelity.integration.test.ts: components are loaded per variant, under that variant's config.

Tests

  • A matrix of 16 instance shapes (comments before, after and around inline, block and text roots; empty and whitespace-only instances), every pair plus some triples, in six placements (table cell, formatting element, <pre>, paragraph), each compared with minifyHtml of the same bytes.
  • A fast-check property over random instance sequences and surrounding author text, 3,000 runs.
  • Five of these fail without the renderer change.

Verification

  • pkg unit: 8,776 pass
  • pkg integration: pass (809)
  • pkg linear-time: 475 pass
  • Cloudflare adapter unit: 563 pass; Netlify adapter unit: 77 pass
  • typecheck, format, spelling: clean

🤖 Generated with Claude Code

With minify.html on, each component instance rendered from a server or
stream script is minified on its own. Where two were written with nothing
between them, the space each kept at its own edge could differ from the
build, which minifies the page once:

- in a table, where a removed comment leaves an empty separator, the space
  landed before the separator instead of after it;
- an instance that leaves nothing at its edge (empty, or only comments and
  whitespace) was treated as a neighbor, so the instance beside it kept or
  doubled a space the build drops.

The finalizer now resolves each instance's neighbors past instances that
leave nothing, and merges the whitespace and separators at each seam the
way the build treats that stretch. The differences were in bytes, not in
what a browser renders.

The fidelity test loaded each root's components once and reused them for
every variant, so some variants paired files loaded with minify.html off
with pages built with it on. No build does that (component files are
minified as they load), and it is how a comment at the top of a component
file reached this code. Components are now loaded per variant.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
@collin-thomas
collin-thomas deleted the fix/request-render-leading-comment branch November 12, 2026 10:15
@collin-thomas

Copy link
Copy Markdown
Collaborator Author

Superseded by the PR from fix-request-render-seam-whitespace: renaming the branch (the shop-preview environment does not deploy branch names with a slash) closed this one.

This branch had an error being deployed

1 failed deployment
shop-preview — 4e2a8f59 Deployed Nov 12, 2026 by collin-thomas via deploy-preview #158
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