Skip to content

Test every JSX text for spaces Next's compiler drops - #263

Merged
MaxGhenis merged 7 commits into
mainfrom
expand-models-space
Nov 14, 2026
Merged

MaxGhenis merged 7 commits into
mainfrom
expand-models-space

Conversation

@MaxGhenis

@MaxGhenis MaxGhenis commented Nov 14, 2026 •

Copy link
Copy Markdown
Contributor

#264 restored five spaces that Next 16.2.6's compiler dropped from policybench.org, such as "frontier modelson 100 households" on /expand. The branch adds app/tests/jsxTextSpacing.test.ts, which fails CI on the next such space before it reaches the site.

The test compiles every JSX text under src/ with Next's own SWC and with TypeScript, which applies JSX's whitespace rules to the text as written. It fails wherever Next's output has no whitespace at a place TypeScript's has some, or shows other characters. Against src/ from before #264 it names the five lines #264 fixed and no others, and it passes on main.

Its rule cases pin the shapes Next mishandles, so a compiler upgrade that changes them fails the test too:

  • leading spaces in a text that holds a decoded entity and a line break;
  • an encoded line break (
) at either end of a text;
  • an encoded space ( ) after a line break at the end of a text.

A third test compiles the three components #264 fixed and requires a space before each of the five phrases. Bun's transpiler keeps the spaces Next drops, so the page test expandPage.test.ts cannot catch them, and the guard compiles with Next's compiler instead.

Lint and bun test tests (207 pass) pass locally at da20531. No file under src/ changes.

🤖 Generated with Claude Code

Next 16.2.6's compiler drops the leading space of a JSX text that spans
more than one line and contains an HTML entity, so policybench.org renders
"52 frontier modelson 100 households" on /expand and four run-together
phrases on the home page. An explicit {" "} puts each space back. A new
test applies the compiler's trigger to every page component, and the
expansion-page test no longer reads React's text separators as spaces.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@vercel

vercel Bot commented Nov 14, 2026 •

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated
policybench-site Ready Ready Preview Nov 14, 2026 8:58pm UTC

Request Review

MaxGhenis and others added 4 commits November 14, 2026 09:24
The test renders with renderToStaticMarkup, which emits no <!-- -->
separators, so the added .replace(/<!-- -->/g, "") changed nothing and
its comment named the wrong cause. The test never saw the /expand defect
because Bun's transpiler keeps the leading space that Next's compiler
drops. The line returns to what main has; a compiler-backed check for the
five fixed spaces follows in the spacing guard test.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
… SWC

The guard's rule cases were checked against Next's compiler only by hand.
The test now loads Next's own SWC binding, compiles each case with it and
with TypeScript, and requires the case to record what Next renders and
whether that drops a space TypeScript keeps. A second check compiles
ExpandCoverageCopy, ModelLeaderboard and Methodology with Next's SWC and
requires whitespace before each of the five phrases policybench.org ran
together. Run against main's three files, it fails on all five and the
guard names the five lines.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
The guard's /&(#\d+|#x[0-9a-f]+|[a-z][a-z0-9]*);/i matched any &name;,
so `{x} after\n one&notAnEntity;s` failed it although Next keeps that
space: the compiler leaves unknown names as written and only a decoded
entity triggers the drop. Probing Next 16.2.6's SWC with 2,425 candidate
names (TypeScript's JSX table, the HTML5 names, case variants) showed it
decodes exactly TypeScript's 253 names, case-sensitively, plus decimal
and lowercase-x hex references with at most nine characters between &
and ;. The guard now reads entities that way. A new test compiles every
listed name and a set of near misses and requires the guard to agree with
the compiler on each; rule cases add an unknown name and a miscased one
(space kept, not flagged) and a named, decimal and hex entity (flagged).

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
The guard required a previous sibling and a literal LF, and looked only
at leading spaces, so it passed three shapes Next 16.2.6's SWC mangles:
a text that opens an element (`before<span> after\n one&apos;s</span>`
renders "beforeafter one's"), a lone CR or U+2028 as the line break, and
an encoded line break at a text's edge (`{x}&#10;word\n next` renders
"{x}word next"). Probing the compiler showed two mechanisms. Next deletes
the leading spaces and tabs of a text that has a decoded entity and any
line break, literal or encoded; @swc/core 1.16.22 keeps them. Every SWC
probed also reads an encoded line break as a source line break, so at
either end of a text it vanishes with the whitespace around it, where
TypeScript and Bun keep it. Whitespace the compiler never trims (&#32;,
&nbsp;, a literal no-break space) keeps the words apart in both.

The guard now reads each text as the compiler does and applies both
rules, stated in the test's header. New rule cases cover each shape and
the kept-whitespace exceptions, each compiled with Next's SWC and checked
against TypeScript's output. No text under src/ matches the wider rule,
and against main's files the guard still names exactly the five lines.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
MaxGhenis added a commit that referenced this pull request Nov 14, 2026
…264)

Next 16.2.6's compiler drops the leading space of a JSX text that spans
more than one line and contains an HTML entity. Five phrases on the home
page and the expansion page lost the space between two words. Each space
moves into an explicit {" "}. No word of the copy changes.

The guard test for this defect is in #263.

Co-authored-by: Claude Fable 5.2 <noreply@anthropic.com>
MaxGhenis and others added 2 commits November 14, 2026 15:53
The spacing guard predicted dropped whitespace from a hand-fitted model of
Next's compiler, and the round-2 review found a shape the model missed: an
encoded space after a line break at the end of a text (`a&apos;\n&#32;`),
which Next drops and TypeScript keeps. The guard now compiles each JSX text
under src/ with Next's SWC and with TypeScript and fails wherever Next shows
no whitespace at a place TypeScript does, or renders other characters, so it
no longer depends on the model. The rule cases gain the reviewer's shape and
still pin the compiler's behavior. SRC now goes through fileURLToPath, so a
checkout path with a space works. Each SWC test gets a 60-second limit.

Against src/ from before #264 the guard names exactly the five lines #264
fixed; on this head all 207 app tests pass.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@MaxGhenis MaxGhenis changed the title Restore the spaces Next drops before multi-line text with an entity Test every JSX text for spaces Next's compiler drops Nov 14, 2026
@MaxGhenis

Copy link
Copy Markdown
Contributor Author

Round 2 of the independent review (Subfleet job 20261114-093549-pb-263-spacing-review-r2) approved with three P2 findings and no P0 or P1. da20531 fixes all three: the guard compares Next's compiler with TypeScript on every JSX text, which catches the reviewer's case of &#32; after a line break at the end of a text; SRC goes through fileURLToPath, so a checkout path with a space works; and the description treats #264's fix as done. With main merged in, the diff touches one file, the test.

@MaxGhenis
MaxGhenis merged commit b2ddefa into main Nov 14, 2026
5 checks passed
@MaxGhenis
MaxGhenis deleted the expand-models-space branch November 14, 2026 21:16

This branch was successfully deployed

1 active deployment
Preview — da205319 Deployed Nov 14, 2026 by vercel[bot]
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