Skip to content

compiler: emit real sourcemap segments for return-JSX functions - #21

Merged
trueadm merged 5 commits into
mainfrom
claude/fervent-ptolemy-9a2108
Jul 6, 2026
Merged

trueadm merged 5 commits into
mainfrom
claude/fervent-ptolemy-9a2108

Conversation

@trueadm

@trueadm trueadm commented Jul 6, 2026 •

Copy link
Copy Markdown
Collaborator

What

compileReturnJsxFunction — the compile path for plain function Foo() { return <jsx>; } components — printed its output with the map-less printNode, so return-JSX functions contributed zero sourcemap segments to the client compile's map. It now prints via printNodeWithMap and threads esrap's per-token mappings back to compile() through the existing ctx._setupMaps side-channel (drained by drainSetupMaps, exactly like component setup statements), plus a declaration anchor per function.

Two output rewrites needed map adjustments:

  • compInlinedSubs splice — when folded-directive helpers are spliced in after the function's opening {, every printed line below shifts down by the inserted line count. Mirrored by splicing the same number of empty mapping lines at that point (the helpers themselves stay unmapped, matching the component path's inlinedSubs).
  • Export wrappers — export shifts only line 0's columns (+7); export default appends an unmapped trailing line and needs no shift.

Why

@octanejs/mdx composes a two-stage map (@mdx-js/mdx map → octane map, via @jridgewell/remapping), and MDX document bodies (_createMdxContent) are exactly the return-JSX shape — so the chained map composed to empty and the pipeline fell back to octane's intermediate-JSX map. With this fix, generated positions trace all the way back to .mdx lines.

The pinned test flipped as designed: packages/mdx/tests/sourcemap.test.ts's it.fails('chains generated positions all the way back to .mdx lines') is now a plain it, and the GAP notes in that file, packages/mdx/src/compile.ts, and docs/mdx-migration-plan.md (gap 4 → FIXED) are removed. The non-empty guard in mdx's compile.ts stays as a defensive fallback.

Reviewer notes

  • This branch includes a cherry-pick of f887fe4 (the @octanejs/mdx Phase-1 commit from claude/objective-khorana-db211b, here as 023f489) — the pinned sourcemap test and the two-stage map machinery live there, not on main. The cherry-pick applied cleanly (that branch's parent is content-identical to main's tip); if the MDX branch merges first, this resolves as a no-op on those files.
  • Printed output is byte-identical (printNodeWithMap returns the same code as printNode, just with mappings), so no runtime/codegen behavior changes.
  • Verified traced positions directly: dynamic holes map to exact source line/column, statements after a directive-helper splice stay aligned, exported declarations anchor to the source declaration.
  • Changeset added (octane patch).

Validation

  • Full monorepo suite: 321 files / 2255 passed + 5 pre-existing expected-fails, zero errors
  • --project octane and --project mdx green individually
  • pnpm typecheck and pnpm format:check clean

🤖 Generated with Claude Code


Note

Medium Risk
Touches core compiler codegen, SSR HTML shape, and hydration alignment; the MDX cherry-pick is large but heavily covered by new tests.

Overview
Octane compiler: compileReturnJsxFunction now prints with printNodeWithMap and feeds esrap segments into the module map via ctx._setupMaps / drainSetupMaps (with anchors for exports and line shifts when directive helpers are spliced), so emitted JS stays the same but devtools can step return-JSX bodies — including MDX _createMdxContent. SSR: value-position return <>…</> in return-JSX functions is emitted through ssrChild([...]) instead of a markerless template walk, matching the client fragment descriptor shape for hydration.

@octanejs/mdx (bundled Phase 1): Adds @octanejs/mdx/server (MDXProvider / useMDXComponents on octane/server), default server providerImportSource, two-stage sourcemaps (SourceMapGenerator + @jridgewell/remapping), client HMR registration for MDXContent, Vite passthrough for ?raw/?url/?inline, and docs/README updates. New tests cover hydration byte-adoption, SSR provider parity, Shiki via rehypePlugins, HMR hot-swap, Vite id rules, and .mdx line tracing in sourcemaps. recmaOctaneAdapter is down to the single _createMdxContent(props) → JSX mount fixup.

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

trueadm and others added 2 commits July 6, 2026 07:29
…provider, shiki, HMR, .md queries, sourcemaps)

Hydration: server-rendered MDX documents now hydrate byte-for-byte. On top of
the host-string-tag ssrComponent fix, the octane server compiler value-lowers
a return-JSX component's returned FRAGMENT through ssrChild([...]) — the same
descriptor array the client mounts via the return-slot childSlot — instead of
template-concatenating children with markerless separators (which silently
duplicated content on hydrate). Both adapter server fixups are now dropped;
recmaOctaneAdapter is down to the single call→JSX ABI rewrite.

SSR provider context: new @octanejs/mdx/server entry mirrors the provider
layer onto octane/server context (the runtimes' stores are disjoint);
server-mode documents default providerImportSource there. The server
MDXProvider threads mappings across a renderToString pass, serializes the
same payload as the components-prop route, and hydrates byte-for-byte into
the client MDXProvider.

Shiki: documented @shikijs/rehype recipe (devDependency only) with
integration tests — client tokens, SSR/client payload parity, hydration.

HMR: .mdx documents fast-refresh. octane's compiler only auto-wraps exported
@{}-form components, so the pipeline appends the identical registration
itself (hmr() wrap on the default export + self-accepting import.meta.hot
block); live mounts re-render edits in place.

.md default-on kept; asset-query imports (?raw/?url/?inline/workers) now pass
through untouched (the transform previously stripped the query before
matching and would have mangled vite's asset-plugin output).

Sourcemaps: two-stage chain (@mdx-js/mdx SourceMapGenerator → octane map,
composed with @jridgewell/remapping) with a non-empty guard. Today the chain
composes empty — octane's compileReturnJsxFunction prints maplessly (gap
noted in the plan doc, pinned it.fails) — so the intermediate-JSX map is kept
as fallback.

mdx suite: 25 → 51 tests. Full monorepo suite, typecheck, format green.

Co-Authored-By: Claude Fable 5 <[email protected]>
compileReturnJsxFunction printed with the map-less printNode, so plain
`function Foo() { return <jsx> }` components contributed zero segments to
the client compile's map — and @octanejs/mdx's two-stage .mdx map (mdx map
→ octane map via @jridgewell/remapping) composed to empty for document
bodies (_createMdxContent is exactly this shape), falling back to the
intermediate-JSX map.

Now it prints via printNodeWithMap and threads esrap's per-token mappings
back to compile() through the existing ctx._setupMaps side-channel (drained
by drainSetupMaps, like component setup statements), plus a decl anchor per
function. The compInlinedSubs splice shifts every printed line below the
opening brace down by the inserted helper lines — mirrored by splicing
empty mapping lines at the same point; the `export ` wrapper shifts only
line 0's columns, and `export default` appends an unmapped trailing line.

Flips the pinned mdx test (sourcemap.test.ts it.fails → it): generated
positions now trace all the way back to .mdx lines. GAP notes removed from
mdx compile.ts and docs/mdx-migration-plan.md (gap 4 → FIXED).

Co-Authored-By: Claude Fable 5 <[email protected]>
@trueadm trueadm changed the title Claude/fervent ptolemy 9a2108 compiler: emit real sourcemap segments for return-JSX functions Jul 6, 2026
trueadm and others added 2 commits July 6, 2026 07:43
…licts

Both conflicts were doc text where this branch's Phase-1 version supersedes
main's intermediate one; kept ours and grafted in main's test-file citations
for gaps 1 and 2.

Co-Authored-By: Claude Fable 5 <[email protected]>
The first highlight pays shiki's engine cold-start (oniguruma WASM +
grammar/theme load) — 5.2s on the Node 22 CI runner, tripping vitest's 5s
default timeout on the first test in the file. The highlighter is
singleton-cached after, so warm it once in a beforeAll with its own 60s
budget instead of inside any test's.

Co-Authored-By: Claude Fable 5 <[email protected]>

@cursor cursor Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cursor Bugbot has reviewed your changes using default effort and found 1 potential issue.

Fix All in Cursor

❌ Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, enable autofix in the Cursor dashboard.

Reviewed by Cursor Bugbot for commit bd714b2. Configure here.

Comment thread packages/octane/src/compiler/compile.js Resolved
Decoded sourcemap rows are dense up to the last line WITH segments, so when
the mappings array ends at the splice line, every line the compInlinedSubs
splice shifts down carries no segments — nothing to realign. Comment only.

Co-Authored-By: Claude Fable 5 <[email protected]>
@trueadm
trueadm merged commit 63e51e8 into main Jul 6, 2026
5 checks passed
@trueadm
trueadm deleted the claude/fervent-ptolemy-9a2108 branch July 6, 2026 09:18
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