Repository navigation
fix(turbopack): scoped CSS in Next builds and TSX parsing for platform flags - #1087
Merged
jonkwheeler merged 9 commits intoNov 12, 2026
Merged
jonkwheeler merged 9 commits into
jonkwheeler merged 9 commits into
Conversation
The loader appended `import "<absolute path>.tsrx?tsrx-css&lang.css"`
for components with a `<style>` block. Turbopack does not resolve
absolute import paths ("server relative imports are not implemented
yet"), so every Next build of a component with scoped styles failed.
Import the sibling resource as `./<basename>?tsrx-css&lang.css`.
Co-Authored-By: Claude Opus 5.5 <[email protected]>
…nents The sibling `?tsrx-css&lang.css` rule set `type: 'css'`. Turbopack then bundled the stylesheet into the server chunk, but Next never linked it into the page when a server component imported it, so a component's scoped styles were missing in `next dev` and `next build` unless a client component imported it. Rename the module with `as: '*.css'` instead, which sends it through Next's own CSS rule. Co-Authored-By: Claude Opus 5.5 <[email protected]>
`replacePlatformFlags` parsed every module with the TSRX parser, so
TSRX's JSX-text rules applied to ordinary `.jsx`/`.tsx` files. Under the
Turbopack platform loader, `<pre>/*</pre>` failed with "Unclosed tag",
and a flag inside `<pre>/* {import.meta.env.platform.web} */</pre>` was
read as a comment and left unreplaced, crashing at runtime.
Parse with acorn-typescript's TSX grammar instead. It lacks some syntax
the TSRX parser reads (phase imports, a trailing comma in `import()`),
so a module it rejects falls back to the TSRX parser, as before.
Co-Authored-By: Claude Opus 5.5 <[email protected]>
…m flags TypeScript files have no JSX, but flag replacement parsed them with JSX enabled, so `<number>value` in a `.ts`, `.mts` or `.cts` module failed with "Unterminated JSX contents" under the Turbopack platform loader. Parse those extensions without JSX. Co-Authored-By: Claude Opus 5.5 <[email protected]>
Co-Authored-By: Claude Opus 5.5 <[email protected]>
acorn-typescript in JSX mode rejects every single-parameter generic arrow without a trailing comma, including `<T extends object>(o: T) => o`, which is valid TSX. Such a module fell back to the TSRX parser, so the JSX-text problems this parser exists to avoid came back, and a later syntax error was reported at the arrow instead of where it is. Allow a constraint or default, as the TSRX parser's own override does. Also pin which error a module neither parser reads reports, and cover `.js`, `.mjs` and `.cjs` filenames. Co-Authored-By: Claude Opus 5.5 <[email protected]>
… module The README and llms.txt still said the stylesheet is handed back as a "CSS module". It is now renamed to `*.css`, so Next links it into App Router pages. The README also notes that the Pages Router rejects the import as global CSS. Co-Authored-By: Claude Opus 5.5 <[email protected]>
`create_tsrx_react_turbopack_css_rule()` and `TsrxReactTurbopackCssRule` lose `type` and gain `as`, a public API removal. Say the scoped-styles fix is for the App Router and add a migration note. Co-Authored-By: Claude Opus 5.5 <[email protected]>
jonkwheeler
marked this pull request as ready for review
October 26, 2026 20:14
This was referenced Oct 27, 2026
…ditions The Turbopack rules match the generated stylesheet with `condition.query`, which `turbopack.rules` accept from Next 16.2.0 (the version history in Next's `turbopack` config docs). Next 16.1.7 rejects the config with "Unrecognized key(s) in object: 'query'", so every build fails, styled or not. Raise the `next` peer range from `>=15.3.0` to `>=16.2.0` and say so in the README and changeset. Co-Authored-By: Claude Opus 5.5 <[email protected]>
Merged
jonkwheeler
added a commit
to jonkwheeler/tsrx
that referenced
this pull request
Nov 12, 2026
main now has tsrx-org#1087's squash commit; merged against the parent commit this branch has so git doesn't redo that work. Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_01FRKmwAwuyPbGQ1ejNqiJ46
jonkwheeler
added a commit
to jonkwheeler/tsrx
that referenced
this pull request
Nov 12, 2026
In error-examples.js, WITHOUT_EXAMPLE keeps this PR's RESERVED_TYPE_ASSERTION entry and main's LET_DECLARATION_NAME in place of the LET_BINDING entry main removed, and KNOWN_PROBLEMS keeps this PR's UNCLOSED_TAG_GENERIC_ARROW record without the two CODE_BLOCK records main dropped. platform.test.js keeps this PR's TypeScript-module test and main's TSX and TypeScript platform tests from tsrx-org#1087. Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_01FRKmwAwuyPbGQ1ejNqiJ46
This was referenced Nov 13, 2026
Closed
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.
Summary
Two Turbopack (Next.js) integration bugs.
Scoped styles in the App Router (#565). Before: any component with a
<style>block failednext buildwith "server relative imports are not implemented yet". After: App Router builds pass and the scoped stylesheet is linked into the page../<basename>?tsrx-css&lang.css.?tsrx-cssrule usedtype: 'css', so Turbopack bundled the CSS into the server chunk and Next never added a<link>for it. The rule now usesas: '*.css', which goes through Next's own CSS rule. Client-component imports already worked and still do.@tsrx/turbopack-plugin-react):create_tsrx_react_turbopack_css_rule()and theTsrxReactTurbopackCssRuletype now haveas: '*.css'instead oftype: 'css'. If you spread or inspect this rule, expectas: '*.css'..tsrxcomponent still fails with Next's "Global CSS cannot be imported from files other than your Custom ". It fails the same way with the oldtype: 'css'rule, so this PR didn't cause it. The README now says so.nextpeer dependency is now>=16.2.0(was>=15.3.0). The rules usecondition.query, which Next'sturbopackconfig docs list as added in 16.2.0. A realnext buildon Next 16.1.7 fails for every page, styled or not, with "Unrecognized key(s) in object: 'query'". On 16.2.0, styled and unstyled builds pass and the stylesheet is linked (b5448a2).Platform flags in ordinary modules (#910). Before: with a platform selected,
<pre>/*</pre>in an ordinary.jsx/.tsxpage failed with "Unclosed tag 'replacePlatformFlags(only the Turbopack platform loader calls it) now parses with acorn-typescript instead of the TSRX parser.<T extends object>(o: T) => o), mirroring the TSRX parser's existing exemption.import defer), a trailing comma inimport(), andfor ((a as T) of x). When it rejects a module, the code falls back to the TSRX parser, so modules that parsed before still parse. If both parsers fail, the acorn-typescript error is thrown, at the real location..ts/.mts/.ctsfiles are parsed without JSX, so<number>valuetype assertions no longer fail with "Unterminated JSX contents" (d826f8f25).Verification
next build(Next 16.2.6, issue #565 script, App Router): styled exits 0 with<link rel="stylesheet">→div.tsrx-…{color:red}, and unstyled exits 0. Without theas: '*.css'change, the styled build passes but has no stylesheet link.next devbehaves the same way: the link is present with this change and absent withtype: 'css'.next build(issue #910 script plus extra cases), before → after:web(<pre>/*</pre>): 1 → 0web-tsx(<pre>// docs</pre>): 1 → 0web-flag(flag between comment-like text): 1 → 0, renders/* true */. Before, prerender failed with "Cannot read properties of undefined (reading 'platform')".web-generic-flag/web-generic-docs(constrained or defaulted generic arrow inpage.tsx): both exit 0.unconfiguredandweb-stringstay at 0.packages/tsrx/tests/utils/platform.test.jsandpackages/turbopack-plugin-react/tests/*. They cover constrained and defaulted generic arrows, the error location after one, the error when neither parser reads a module, and.js/.mjs/.cjsfilenames. Each failed before its fix.npx vitest run --project tsrx-utils --project turbopack-plugin-react: 1560 passed.npx vitest run(before the review fixes): 9986 passed, 28 failed. 27 were 5s/30s timeouts while the machine's load average was about 75–97, and 1 was a shiki tokenizer error in the vscode grammar test. All 13 affected files passed when re-run on their own; 4 of them needed--testTimeout=120000.pnpm typecheckclean,prettier --checkclean on changed files,pnpm changeset:checkpasses.Issues
Fixes #565
Fixes #910
🤖 Generated with Claude Code
Note
Medium Risk
Touches Next/Turbopack integration (peer bump, rule API change) and platform transform parsing for all ordinary modules when a platform is set; behavior is well-tested but affects build-time CSS linking and flag rewriting.
Overview
Fixes App Router Turbopack builds for
.tsrxcomponents with scoped<style>blocks: the loader now injects a relative?tsrx-cssimport (Turbopack rejects absolute paths), and the CSS Turbopack rule usesas: '*.css'instead oftype: 'css'so Next links the stylesheet on server components in dev and build.create_tsrx_react_turbopack_css_rule()/TsrxReactTurbopackCssRuleexpose that shape change;nextpeer is>=16.2.0forcondition.queryin turbopack rules. Pages Router behavior is unchanged (still hits Next’s global CSS restriction).Platform flag replacement in ordinary
.js/.jsx/.ts/.tsxnow parses with acorn-typescript via newparse_ordinary_module, so comment-like JSX text (e.g.<pre>/*</pre>) is not treated as TSRX syntax, flags in{…}next to that text are rewritten, and.tsfiles keep<T>valueas type assertions. Constrained/defaulted generic arrow params are allowed in TSX; syntax only the TSRX parser understands still falls back toparse_module, with acorn’s error surfaced if both fail.Reviewed by Cursor Bugbot for commit b5448a2. Bugbot is set up for automated code reviews on this repo. Configure here.