Skip to content

compiler: classify _/$-prefixed identifier JSX tags as component references - #17

Merged
trueadm merged 1 commit into
mainfrom
claude/admiring-elbakyan-300b77
Jul 5, 2026
Merged

trueadm merged 1 commit into
mainfrom
claude/admiring-elbakyan-300b77

Conversation

@trueadm

@trueadm trueadm commented Jul 5, 2026 •

Copy link
Copy Markdown
Collaborator

What changed

isComponentTag in packages/octane/src/compiler/compile.js classified an identifier JSX tag as a component only when it matched /^[A-Z]/. JSX semantics (Babel/TypeScript's isCompatTag, ESTree) say an identifier tag is a host string tag only when it starts with a lowercase ASCII letter — anything else, including _- and $-prefixed identifiers, is a component reference.

Before this fix, <_Inner/> miscompiled in both modes:

  • client: _$template("<_Inner></_Inner>") — a host template that renders a literal <_inner> element
  • server: baked into the static HTML string as literal <_Inner> markup (or an Invalid tag: _Inner throw via ssrHostElement's VALID_TAG_NAME guard on non-static paths)

Now both modes emit a component reference: _$createElement(_Inner, {}) / _$ssrComponent(__s, _Inner, {}). Lowercase and dashed tags (<div>, <my-element>) stay host tags, matching Babel (a dashed tag is not a valid JS identifier, so it can never be a reference).

isComponentTag is the single decision point — the client lowering, jsxElementToCreateElement, and the server emitter all route through it. I audited the compiler for other case-based host-vs-component checks and found none (the remaining /^[A-Z]/ uses are event-name and use[A-Z] hook detection).

@octanejs/mdx simplification

The gap was found while building the MDX binding: MDX names its body component _createMdxContent, and recmaOctaneAdapter renamed it to MDX$CreateMdxContent purely to dodge this miscompile. That rename is now dropped. The bare-call→JSX rewrite (_createMdxContent(props) → <_createMdxContent {...props}/>) is kept — that adaptation exists for octane's (props, __s, __extra) component ABI, not for tag classification.

Tests

  • New packages/octane/tests/component-tag-names.test.ts: <_Inner/> and <$Inner/> compile as component references in client and server modes; lowercase/dashed tags remain host tags.
  • packages/mdx/tests/compile.test.ts updated for the dropped rename (asserts the body mounts via _$createElement(_createMdxContent, …) with no direct-call shape).
  • Changeset added (octane patch).

Full pnpm test (312 files, 2205 passed + 5 pre-existing expected fails), pnpm typecheck, and pnpm format:check are all green.

🤖 Generated with Claude Code


Note

Medium Risk
Touches the central isComponentTag gate used by client and server codegen, so misclassification could affect any JSX with non-lowercase identifier tags; scope is narrow and covered by new tests.

Overview
Octane’s JSX lowering now treats identifier tags as host elements only when the name starts with a lowercase ASCII letter and has no dash—aligned with Babel/TS isCompatTag. Tags like <_Inner/> and <$Inner/> compile to component references (createElement / ssrComponent) instead of string host tags or broken SSR.

@octanejs/mdx drops the recmaOctaneAdapter rename from _createMdxContent to MDX$CreateMdxContent; the bare-call→JSX rewrite for the no-layout branch is unchanged for the component ABI.

New component-tag-names tests cover client/server; MDX compile tests expect _createMdxContent in emitted code.

Reviewed by Cursor Bugbot for commit 59c57d3. Bugbot is set up for automated code reviews on this repo. Configure here.

…rences

JSX semantics (Babel/TS isCompatTag) treat an identifier tag as a host
string tag only when it starts with a lowercase ASCII letter; isComponentTag
used /^[A-Z]/, so <_Inner/> and <$Inner/> miscompiled to host string tags
(client: _$template("<_Inner></_Inner>"), server: literal markup or an
Invalid-tag throw). Host tags remain lowercase-start or dashed identifiers
(<my-element>).

Drop @octanejs/mdx's MDX$CreateMdxContent rename workaround for this gap
(the bare-call-to-JSX rewrite stays — that's the component-ABI concern).

Co-Authored-By: Claude Fable 5 <[email protected]>
@trueadm
trueadm merged commit 4c5b1d0 into main Jul 5, 2026
5 checks passed
@trueadm
trueadm deleted the claude/admiring-elbakyan-300b77 branch July 5, 2026 22:07
trueadm added a commit that referenced this pull request Jul 6, 2026
Merges origin/claude/serene-lehmann-99e802 (PR #18): ssrComponent's string
branch now inlines a template call site's __schildren$N render-fn output as
the element's PLAIN content (rawInner in ssrHostElement) — one outer
<!--[-->…<!--]--> block around the element, no nested block around its
content — per review feedback on #18 flagging the nested-block shape (which
main got via #19) as a bug. Also brings #18's MDX cleanup: the server-mode
_components.* value-hole workaround is dropped now that the runtime handles
string tags natively (merge keeps main's #17 _createMdxContent handling).

Client reworked to match: componentSlot's string branch renders through a
new hostStringTagBody instead of hostElementBody. The element part is the
same de-opt machinery (adopt/create/patch, refs, delegated events, mismatch
recovery), but the compiled children render-fn now renders through ONE
self-bounding Block whose range is all of the element's content — parentNode
= el, no comment markers — so client mounts emit no inner markers and
hydration adopts the server content directly off el.firstChild. A render
prop returning a descriptor still routes through renderBlock's return-slot
(childSlot, block-wrapped), mirroring the server's ssrChild normalization.
Value-position function children (createElement) keep the marker-wrapped
hostElementBody/childSlot path — the server block-wraps those.

Tests unified from both branches: #18's value-position SSR/hydration suite +
this branch's template-position mount/update/hydration suite, all pinned to
the inline shape, plus new template-position SSR pins (component child stays
block-wrapped inside inline content; void; event/ref filtering).

Co-Authored-By: Claude Fable 5 <[email protected]>
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