Repository navigation
fix(react): skip raw-only .tsrx on HMR and reuse authored Suspense and Fragment imports - #1102
Merged
jonkwheeler merged 2 commits intoNov 12, 2026
Merged
Conversation
…srx on HMR handleHotUpdate compiled every changed .tsrx file to refresh its stylesheet before checking whether a stylesheet module existed. A file imported only as `?raw` (an incomplete docs example, say) failed to compile, and Vite sent an HMR error instead of the raw update. Look the stylesheet module up first and compile only when it exists, as the Hono plugin already does. Fixes tsrx-org#566 Co-Authored-By: Claude Opus 5.5 <[email protected]>
The shared JSX import injector always added
`import { Suspense } from '<source>'` for `@try … @pending` and
`import { Fragment } from '<source>'` for keyed fragment bodies, even
when the module already imported that name from the same source. The
duplicate declaration failed the build with "Identifier `Suspense` has
already been declared".
Skip the injected import when the module already has a value import of
the same name and local from the same source. React, Preact and Hono
share this injector.
Fixes tsrx-org#862
Co-Authored-By: Claude Opus 5.5 <[email protected]>
jonkwheeler
marked this pull request as ready for review
October 26, 2026 19:57
This was referenced Oct 27, 2026
Merged
jonkwheeler
added a commit
to jonkwheeler/tsrx
that referenced
this pull request
Nov 12, 2026
main now has tsrx-org#1102'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
main now has tsrx-org#1102'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
that referenced
this pull request
Nov 12, 2026
…under private names (#1175) * fix(core): import generated Suspense, Fragment and TsrxErrorBoundary privately The import injector added `Suspense`, `Fragment` and `TsrxErrorBoundary` under their public names, and the generated elements referenced those names. Any other authored binding with one of them broke the build ("Identifier `Suspense` has already been declared") for a type-only, default, namespace or other-source import, or silently replaced the generated element for a setup local or a `@for (const Fragment of ...)` loop variable. Import them as `__Suspense`, `__Fragment` and `__TsrxErrorBoundary`, as the injector already does for `mergeRefs`, and reference those aliases from the generated elements, including Hono's `fallbackRender` boundary. This replaces the same-name import reuse from #1102, which no longer has anything to reuse. Vue imports `TsrxErrorBoundary` itself for the core-generated boundary, so its injector takes the alias too, and it no longer merges that value import into an authored `import type` declaration, where it would be erased. Fixes #1141 * fix(core,vue,solid): keep directives first and bind Vue's generated Suspense Every import injector put its imports at index 0, ahead of a `'use client'` or `'use server'` directive, which then stopped being a directive. Any module using `@pending`, `@catch`, a keyed fragment row, a dynamic tag or another construct with a generated import lost its directive; Next.js treated a `'use client'` .tsrx module as a server component ("You're importing a module that depends on `useState` into a React Server Component module"). Insert generated imports (and the type-only style anchors) after the directive prologue in the core, Vue and Solid injectors. Vue's `ensure_named_import` also counted an inline `type` specifier as the value import, so `import { type Suspense } from 'vue'` with `@pending` left `Suspense` unbound. Require a value specifier, and import Vue's generated `Suspense` as `__Suspense` like the core transform does, so the value import never redeclares an authored binding. vue-jsx-vapor compiles the aliased element the same way. * test: expect the private generated names in main's @Try and @pending tests This branch imports the generated Suspense and TsrxErrorBoundary as `__Suspense` and `__TsrxErrorBoundary`. Tests that main added since (the TsrxTryBody fallback, @Try site keys, inline @pending bodies, Vue's keyed-slot computed import and element-child boundary) matched the public names. They now match the aliases, the react-server import check reads the imported name of each specifier, and Vue's Suspense import tests expect the generated `Suspense as __Suspense` beside any authored `Suspense` import. * test: expect the private Fragment alias in main's nested keyed @for test Main's #1136 added a test that matches `<Fragment key={group.id}>` for a keyed row that renders a nested @for. This branch imports the generated Fragment as `__Fragment`, so the test now matches that name. Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_01FRKmwAwuyPbGQ1ejNqiJ46
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
Raw-only
.tsrxassets on HMR (#566). Before: the React and Preact Vite plugins compiled every changed.tsrxfile inhandleHotUpdateto refresh its stylesheet, before they checked whether a stylesheet module existed. A file imported only as?raw(an incomplete docs example, say) failed to compile, and Vite sent an HMR error instead of the raw-string update. After: the stylesheet module is looked up first, and the file is compiled only when one exists, as the Hono plugin already does. Vue and Solid compile inload, so they were not affected.Authored
Suspense/Fragmentimports (#862). Before: the shared JSX import injector in@tsrx/corealways addedimport { Suspense } from '<source>'for@try … @pendingandimport { Fragment } from '<source>'for a keyed@forwith a fragment body. A module that already imported the same name from the same source ended up with two declarations, and the build failed withIdentifier `Suspense` has already been declared. After: the injector skips its import when the module already has a value import of that name, with the same local name, from the same source. React, Preact and Hono share this injector. Vue's injector already merged imports this way.Verification
packages/vite-plugin-react/tests/basic.test.jsandpackages/vite-plugin-preact/tests/basic.test.js: a hot update for a file whose only module isExample.tsrx?raw, with incomplete source, returns the modules unchanged. It threwUnclosed tag '<section>'before the fix.packages/tsrx-react/tests/basic.test.js: an authoredSuspenseimport with@try … @pending, and an authoredFragmentimport with a keyed fragment@for, each compile to exactly one import of that name. Both had two before the fix.updatefor/Example.tsrx?rawwith React and Preact, and the [Bug]: React Suspense and Fragment imports collide with generated template imports #862 build-and-render script renders<b>native</b><p>ready</p>and both keyed rows.npx vitest run --project tsrx-react --project tsrx-preact --project tsrx-hono --project vite-plugin-react --project vite-plugin-preact: 2273 passed.npx vitest runpassed 10038 tests. Threecontent-mappertests that spawntschit the 5s timeout under machine load (load average about 60) and pass when rerun with a longer timeout.pnpm typecheckis clean,pnpm changeset:checkpasses, and Prettier is clean on every changed file.Related
Fixes #566
Fixes #862
🤖 Generated with Claude Code
Note
Low Risk
Targeted compiler and Vite HMR guard changes with new regression tests; no auth, data, or broad API surface changes.
Overview
Fixes two build/HMR edge cases in the React/Preact stack.
Authored
Suspense/Fragmentimports:@tsrx/core’s JSX import injector now skips addingSuspenseorFragmentwhen the module already has a matching value import from the same source with the same local name. That lets you mix native<Suspense>/<Fragment>with@try … @pendingor keyed@forfragment bodies without a duplicate-binding compile error.?raw-only.tsrxon HMR: The React and Preact Vite plugins look up the stylesheet module before reading the file for CSS cache updates. Files with no scoped CSS module (typical when the only consumer is?raw) no longer get compiled on hot update, so incomplete snippet sources can refresh as raw text instead of failing the TSRX parser.Reviewed by Cursor Bugbot for commit 2cde29a. Bugbot is set up for automated code reviews on this repo. Configure here.