Repository navigation
fix(core): prefix a component's local catch helper with its name - #1229
Merged
jonkwheeler merged 12 commits intoNov 12, 2026
Merged
Conversation
…zed binding Static JSX is hoisted to a module-level const placed before the top-level statement it came from, so its tag is read when the module loads. A tag that reads the class the JSX is in (`<Screen.Tag>` in a method of `class Screen`), a const or class declared later, or `this` then threw on import: "Cannot access 'Screen' before initialization". Hoisting now skips JSX whose tag reads `this` or a name that a top-level statement binds at or after the one the JSX is in. Function declarations and imports are initialized before the module body runs, so tags that read them are still hoisted. Fixes tsrx-org#204 Co-Authored-By: Claude Opus 5.5 <[email protected]>
Since tsrx-org#790 a raw `<script>` keeps its body in `content`, and the walk lowers it when it reaches the element. An element in an expression container or attribute value of static JSX is reached only in the render output the walk returns, which a hoisted static has already left. So `<div>{<script type="application/json">{"a":1}</script>}</div>` and a script passed as a prop rendered an empty script on every target. Hoisting now lowers those scripts with the platform's element transform, as the walk would. Fixes tsrx-org#845 Co-Authored-By: Claude Opus 5.5 <[email protected]>
…odule binding The tsrx-org#204 fix checked tags only against top-level declarations, by position. It still hoisted `<super.Tag>` (a module that fails to parse), `<Screen.Tag>` in `const C = class Screen { … }` (`Screen is not defined`), tags that read a static block's or block's bindings, and member tags such as `<Menu.Item>` whose property is assigned after the module loads, along with tags that read a `let` or `var` assigned later. Each tag now resolves through the scopes it is written in, and static JSX is hoisted only when every tag that reads a binding resolves to an import, a function declaration, or a `const` or class declared in an earlier statement. A member tag that starts with a function or class declared in the module is read at render time, as is a tag that reads `this`, `super`, a local binding, a `let`, `var`, enum, namespace or import alias, or a name the module does not declare. Intrinsic tags like `<div>` read no binding, so a later `const div` no longer stops them from being hoisted. Related: tsrx-org#204 Co-Authored-By: Claude Opus 5.5 <[email protected]>
…ction
A component's statics and helper components go to module level through
the top-level statement that holds it, and `expand_component_helpers`
finds them only through nodes that are not functions. A component
declared inside another function (`function outer() { function App() {
return <div>hi</div> } }`) still hoisted its JSX, so it returned
`App__static1`, which was never declared, and threw a ReferenceError
when it rendered.
Such a component now gets no helper state, so it lowers its statics
and helpers in place, as code outside a component does.
Co-Authored-By: Claude Opus 5.5 <[email protected]>
A member tag on a `const` declared earlier was still hoisted, so the
compound-component pattern `const Menu = …; <Menu.Item />` with
`Menu.Item = …` (or `Object.assign(Menu, { Item })`) after it read
`Menu.Item` when the module loaded and rendered an undefined type.
A member tag now stays at render time unless it starts with an import
(named, default or namespace). Plain tags keep the earlier rules.
Related: tsrx-org#204
Co-Authored-By: Claude Opus 5.5 <[email protected]>
Giving such a component no helper state, to keep its statics and helper components in place, also moved its spread temporary to the fallback name `_tsrx_spread_props_N`, which can shadow or redeclare a user variable of that name. The component now gets a local helper state again: it names things as it did on main and keeps its statics and helper components in place. The spread temporary, in core and in Solid, also skips any name the module source already uses. Co-Authored-By: Claude Opus 5.5 <[email protected]>
…ing JSX The scope walk that decides whether a static's tags can be read at module level took each `case` of a `switch` as its own scope, and gave a dotted namespace's body none of the inner names. A tag that read a `const` from an earlier case, or `Foo` inside `namespace Outer.Foo`, was hoisted to module scope, where it named a different binding. Collect every case's declarations for the whole `switch`, and add each inner name of a dotted namespace for the code inside it. Fixes tsrx-org#1160 Co-Authored-By: Claude Opus 5.5 <[email protected]>
In a namespace body a name can read an export of any declaration of the
namespace: in `namespace Outer { export function Foo() {} }` followed by
`namespace Outer { … <Foo /> … }`, TypeScript reads `Foo` as `Outer.Foo`.
Module level can't see that, so a static hoisted out of the second block
read the module's `Foo`. Give a component in a namespace body a local
helper state, as one inside another function gets, so its statics and
helper components stay in place. That covers a dotted namespace's inner
names too, so the scope walk no longer adds them.
Related: tsrx-org#1160
Co-Authored-By: Claude Opus 5.5 <[email protected]>
Vue renders a `@catch` body under `@pending` through a generated helper component. At module level it is named `App__StatementBodyHook1`. A component inside another function or a namespace has a local helper state, and the helper was then declared in place under the bare name `StatementBodyHook1`: a setup local of that name failed the build with a duplicate declaration, and a binding of that name in the enclosing function was shadowed, so the fallback rendered the helper itself. The local helper now takes the component prefix as well, and its `typeof` aliases are named after it. Co-Authored-By: Claude Opus 5.5 <[email protected]>
A generated helper named `App__StatementBodyHook1` could still collide with, or shadow, an authored binding of that exact name, at module level and, since the previous commit, in a component inside a function or a namespace. Its name now skips any identifier the module source already uses, the way the spread temporary does since tsrx-org#1121. Co-Authored-By: Claude Opus 5.5 <[email protected]>
`source_mentions_identifier` put the name into a regular expression as written. A component named `App$` gives helper names like `App$__StatementBodyHook1`, where `$` reads as an end anchor, so the scan never matched and an authored binding of that name was declared a second time. The spread temporary of tsrx-org#1121 uses the same scan. Co-Authored-By: Claude Opus 5.5 <[email protected]>
jonkwheeler
marked this pull request as ready for review
October 28, 2026 01:04
This was referenced Oct 28, 2026
jonkwheeler
added a commit
to jonkwheeler/tsrx
that referenced
this pull request
Oct 29, 2026
A static was always named `App__static<n>`, so an authored `const App__static1` in the component captured the static's references, and one at module level redeclared it. The name now skips any name the module source already uses, through the same check as the spread-props temporaries, which now also escapes a `$` in the name (as tsrx-org#1229 does). The reassignment of a function tag after the module loads stays a known limitation, now noted where the hoistable tags are collected. Co-Authored-By: Claude Opus 5.5 <[email protected]>
jonkwheeler
added a commit
to jonkwheeler/tsrx
that referenced
this pull request
Oct 29, 2026
Solid names the temporary that holds a host element's spread props
beside a `ref` itself when the element sits in a branch (`@if`,
`@for`). Its check for a name the module already uses put the name into
a regular expression as written, so with a component named `App$` the
`$` read as an end anchor and the check never matched: the generated
`let App$__spread_props1` shadowed an authored binding of that name,
and `title={App$__spread_props1}` read the props bag.
Use core's scan, which escapes `$` since tsrx-org#1229.
Co-Authored-By: Claude Opus 5.5 <[email protected]>
main now has tsrx-org#1187'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
…ent (#1259) * fix(core): declare a capture-free local helper beside its component A component inside another function or a namespace declared its helper components in its setup, so every instance of the component defined them again: on Vue, each instance called `defineVaporComponent` for its `@catch` helper. A helper that reads nothing from the component's scope now goes beside the component instead, in the statement list that holds it. It may take only its own transient props (the `@catch` parameter), and its body may name no binding the component declares outside the helper's source, at any depth. A helper that reads a setup binding, a prop or a callback parameter stays in the setup. A component with no statement list in its own enclosing function, such as one in an expression-bodied arrow, keeps its helpers in place too. * fix(core): keep a local helper in place when it can read the component `helper_captures_nothing` and `has_statement_list_beside` missed some bindings and scopes, so a helper that reads component state could be hoisted beside the component, where that state is out of scope: - A function expression's own name is bound inside it, so a `@catch` body that renders `<Tree />` inside `function Tree()` lost `Tree`. - Enums, namespaces, type aliases, interfaces and type parameters declared in the component count as captures. A hoisted helper threw on `E.A`; the type ones only broke the editor. - A component in the body of a `for`, `for…in`, `for…of`, `while` or `if` without braces, in a labeled statement, a `with` body or a `catch` clause keeps its helpers in place: the loop variable of `for (const label of labels) apps.push(function App() @{ … })` is out of scope before the loop. - A component in a `switch` case's test keeps its helpers in place, since only a case's statements are a statement list. - A component that calls `eval` directly keeps its helpers in place, as `eval` can read any of its bindings by name. * fix(core): keep a local helper inside the class of its component The walk from a component up to the statement list its helpers go into crossed classes. For a component in a static method, the helper landed before `class Holder`, where `Holder.#m` is an early SyntaxError ("Private field '#m' must be declared in an enclosing class"), so the module failed to load. In a named class expression, `Inner.v` threw a ReferenceError at render, since the class's own name is bound only inside it. Stop at ClassBody, ClassDeclaration and ClassExpression, and keep the helper in the component's setup there. A component in a static block still has the block's own statement list, inside the class. * fix(solid): escape $ when scanning the source for a spread temporary Solid names the temporary that holds a host element's spread props beside a `ref` itself when the element sits in a branch (`@if`, `@for`). Its check for a name the module already uses put the name into a regular expression as written, so with a component named `App$` the `$` read as an end anchor and the check never matched: the generated `let App$__spread_props1` shadowed an authored binding of that name, and `title={App$__spread_props1}` read the props bag. Use core's scan, which escapes `$` since #1229. * test(solid): name the spread temporary of two host spreads beside a ref Main now keeps a lone host spread's `ref` as written on Solid, so the branch test that checked the `$`-escaped spread temporary no longer produced one. Give the element a second spread: Solid then still binds a named `spread_ref_bags` group, which must skip `App$__spread_props1` when the component declares it. Without the escaped scan the group is `App$__spread_props1` again. 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
) * perf(core): hoist static JSX that an expression container renders React, Preact and Hono hoisted a static element written bare in a component's output, but not the same element inside an expression container: `<>{<div> 123 </div>}</>` kept the inner `<div>` in the render. A static element in a container is now hoisted the same way, wherever the container sits in the rendered JSX: in an element's or a fragment's children, in an attribute value other than `key` and `ref`, in either branch of `?:`, on the right of `&&`, `||` and `??`, and in a nested container. A static fragment in a container keeps its children, each hoisted on its own, and consecutive statics stay separate, so the children React sees keep their shape. An element with a `key`, JSX that reads a binding, a bare child of a dynamic element, and JSX inside a callback, an array or any other expression stay in place. Solid, Vue and Hono DOM don't hoist, so their output is unchanged. Fixes #81 * fix(core): keep the parsed tree authored and leave maybe-unrendered components in place Two fixes to hoisting static JSX from expression containers (#81): - The container walk replaced nodes in place, so the parsed tree that compile_to_volar_mappings returns as sourceAst, and that editor features read, held `App__static1` in place of the authored JSX. It now copies each node on the way to a hoisted element. - A static reads its tags when the module loads, so `{false && <ui.Button />}` read `ui.Button` at import, which throws in a cyclic import. In a `?:` branch or on the right of `&&`, `||` or `??`, only host elements whose subtree has no component or member tag are hoisted now. Unconditional containers still hoist as bare statics do. * fix(core): name a hoisted static apart from names the source uses A static was always named `App__static<n>`, so an authored `const App__static1` in the component captured the static's references, and one at module level redeclared it. The name now skips any name the module source already uses, through the same check as the spread-props temporaries, which now also escapes a `$` in the name (as #1229 does). The reassignment of a function tag after the module loads stays a known limitation, now noted where the hoistable tags are collected. Co-Authored-By: Claude Opus 5.5 <[email protected]>
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.
Stacked on #1187; review the commits after e1aeccf; merge after #1187.
Summary
Vue: the
@catchhelper of a component inside a function or a namespace takes the component's name as a prefix (#1200). Vue renders a@catchbody under@pendingthrough a generated helper component. At module level it isApp__StatementBodyHook1. Since #1121 and #1187, a component inside another function or a namespace keeps its helpers in place, and the helper was then declared under the bare nameStatementBodyHook1. Now it isApp__StatementBodyHook1there too, and itstypeofprop aliases are named after it (_tsrx_App__StatementBodyHook1_<binding>).The helper's name skips names the module source already uses. Like the spread temporary since #1121, the helper's name moves on to the next number when the source already has that identifier, so an authored
App__StatementBodyHook1(at module level, or in a component inside a function or a namespace) getsApp__StatementBodyHook2beside it instead of a duplicate declaration or a shadowed binding. Output is unchanged for a module that doesn't use the name. The scan now escapes$, which is both an identifier character and a regex anchor: with a component namedApp$, it never matchedApp$__StatementBodyHook1. #1121's spread temporary uses the same scan.Before → after, compiling with
@tsrx/vueand transforming with Vite'stransformWithOxc:const StatementBodyHook1in the setup of a component inside a functionIdentifier `StatementBodyHook1` has already been declaredApp__StatementBodyHook1export namespace Views { … }Identifier `StatementBodyHook1` has already been declaredconst StatementBodyHook1 = 'outer: 'in the enclosing function, read in the@catchbodyfunction StatementBodyHook1(__props) …) in place of'outer: 'outer: pending catch boomApp__StatementBodyHook1)The helper is still created only by Vue (
createHookSafeHelperhas no other caller), so React, Preact, Hono and Solid output is unchanged.Verification
packages/tsrx-vue/tests/basic.test.js: the three shapes above (setup local inside a function, setup local inside a namespace, enclosing-function binding). Each checks that the bare name is declared only by the author and that the helper isApp__StatementBodyHook1. All 3 fail on fix(core): see switch-case and dotted-namespace bindings before hoisting JSX #1187's head.const App__StatementBodyHook1in the enclosing function and at module level, read in the@catchbody. The helper becomesApp__StatementBodyHook2and the authored binding is declared once. Both fail before the second commit (duplicate declaration). Plus a component namedApp$beside an authoredApp$__StatementBodyHook1, which failed before the third commit.local-helper-names(run by the Vue runtime suite through Vite and vue-jsx-vapor): a component inside a function whose@catchbody under@pendingreads an enclosingStatementBodyHook1while a child throws. It renderedfunction StatementBodyHook1(__props) …before and rendersouter: pending catch boomnow. The fixture sits in its own module so the helper is that module's first,StatementBodyHook1.npx vitest run: 10171 passed, 0 failed.pnpm typecheckclean,pnpm changeset:checkpasses, Prettier clean on changed files.Not changed:
defineVaporComponent(…)call still runs in the component's setup, so each instance ofAppdefines its own helper component. Declaring it once beside the component, in the enclosing function or namespace body, would be a separate change.Related
Fixes #1200
Related: #1121, #1187
🤖 Generated with Claude Code
Note
Medium Risk
Changes Vue-specific JSX lowering for Suspense catch helpers and identifier collision avoidance; scope is narrow but affects generated component declarations and runtime binding resolution.
Overview
Vue
@catchhelper components (emitted under@pendingvia Suspense) now always use the owning component's name prefix (e.g.App__StatementBodyHook1), including whenApplives inside another function or namespace—instead of the bareStatementBodyHook1that could redeclare a setup local or shadow an enclosing binding at runtime.The compiler
create_helper_component_idpicks the nextStatementBodyHook<n>name with that prefix and skips any identifier the module source already mentions, so authored names likeApp__StatementBodyHook1getApp__StatementBodyHook2instead of colliding.source_mentions_identifiernow escapes$so names on components likeApp$are detected correctly.Compile and shared runtime tests cover nested scopes, shadowing, and prefix collision; other targets are unchanged because only Vue uses this helper path.
Reviewed by Cursor Bugbot for commit ad373db. Bugbot is set up for automated code reviews on this repo. Configure here.