Repository navigation
compiler: emit real sourcemap segments for return-JSX functions - #21
Merged
Merged
Conversation
…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]>
…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]>
There was a problem hiding this comment.
Cursor Bugbot has reviewed your changes using default effort and found 1 potential issue.
❌ 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.
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]>
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.

What
compileReturnJsxFunction— the compile path for plainfunction Foo() { return <jsx>; }components — printed its output with the map-lessprintNode, so return-JSX functions contributed zero sourcemap segments to the client compile's map. It now prints viaprintNodeWithMapand threads esrap's per-token mappings back tocompile()through the existingctx._setupMapsside-channel (drained bydrainSetupMaps, exactly like component setup statements), plus a declaration anchor per function.Two output rewrites needed map adjustments:
compInlinedSubssplice — 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'sinlinedSubs).exportshifts only line 0's columns (+7);export defaultappends an unmapped trailing line and needs no shift.Why
@octanejs/mdx composes a two-stage map (
@mdx-js/mdxmap → 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.mdxlines.The pinned test flipped as designed:
packages/mdx/tests/sourcemap.test.ts'sit.fails('chains generated positions all the way back to .mdx lines')is now a plainit, and the GAP notes in that file,packages/mdx/src/compile.ts, anddocs/mdx-migration-plan.md(gap 4 → FIXED) are removed. The non-empty guard in mdx'scompile.tsstays as a defensive fallback.Reviewer notes
f887fe4(the @octanejs/mdx Phase-1 commit fromclaude/objective-khorana-db211b, here as023f489) — 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.printNodeWithMapreturns the same code asprintNode, just with mappings), so no runtime/codegen behavior changes.octanepatch).Validation
--project octaneand--project mdxgreen individuallypnpm typecheckandpnpm format:checkclean🤖 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:
compileReturnJsxFunctionnow prints withprintNodeWithMapand feeds esrap segments into the module map viactx._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-positionreturn <>…</>in return-JSX functions is emitted throughssrChild([...])instead of a markerless template walk, matching the client fragment descriptor shape for hydration.@octanejs/mdx (bundled Phase 1): Adds
@octanejs/mdx/server(MDXProvider/useMDXComponentsonoctane/server), default serverproviderImportSource, two-stage sourcemaps (SourceMapGenerator+@jridgewell/remapping), client HMR registration forMDXContent, Vite passthrough for?raw/?url/?inline, and docs/README updates. New tests cover hydration byte-adoption, SSR provider parity, Shiki viarehypePlugins, HMR hot-swap, Vite id rules, and.mdxline tracing in sourcemaps.recmaOctaneAdapteris 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.