feat(jsx-compiler): add JSX/TSX compiler package for React SSR#154
Open
YusukeHirao wants to merge 3 commits into
Open
feat(jsx-compiler): add JSX/TSX compiler package for React SSR#154YusukeHirao wants to merge 3 commits into
YusukeHirao wants to merge 3 commits into
Conversation
Add @kamado-io/jsx-compiler, a page-compiler compileHooks implementation that renders JSX/TSX components to static HTML via React's renderToStaticMarkup (no hydration, no client JS). JSX/TSX is bundled with esbuild and executed through node:module's registerHooks() (a synchronous custom ESM loader), avoiding any disk I/O for the compiled component. Also upgrade @kamado-io/script-compiler's esbuild dependency to 0.28.1: 0.27.4 crashes esbuild's IPC channel when metafile: true is combined with a build failure, which jsx-compiler's error-path tests exercise.
|
Bugbot is not enabled for your account, so this pull request was not reviewed. Enable Bugbot in the Cursor dashboard to get automatic reviews on future PRs. |
… by filePath Two incremental-build correctness bugs found in review: - createCompileHooks() never exposed a cacheDigest, and page-compiler omits function values (compileHooks included) from its own digest — relying on the config file hash to cover them. That hash can't see an esbuild/react/react-dom upgrade or an options change coming from another module, so an incremental build could silently keep serving stale HTML after either. compileJsx() now exposes cacheDigest() (esbuild/React versions + JsxCompilerOptions), copied onto the main/layout wrappers and folded into page-compiler's own cacheDigest via a new CompilerFunction<M>.cacheDigest hook (mirrors kamado/compiler's CustomCompileFunction.cacheDigest). - compileJsx()'s component cache was keyed by resolveDir+source only, so two byte-identical files in the same directory would share a compiled module — and since the bundle embeds `//# sourceURL=` for whichever file compiled first, a second file's runtime errors would misattribute to the first file's path. filePath is now part of the cache key.
|
Bugbot is not enabled for your account, so this pull request was not reviewed. Enable Bugbot in the Cursor dashboard to get automatic reviews on future PRs. |
…cacheDigest caveat Front-load "only relevant if you use a non-default jsxImportSource" so default (react) users can tell at a glance the item doesn't apply to them, instead of reading the whole paragraph to find that out.
|
Bugbot is not enabled for your account, so this pull request was not reviewed. Enable Bugbot in the Cursor dashboard to get automatic reviews on future PRs. |
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
@kamado-io/jsx-compiler, a new@kamado-io/page-compilercompileHooksimplementation that renders JSX/TSX components to static HTML via React'srenderToStaticMarkup(SSR only — no hydration, no client JS shipped)node:module'sregisterHooks()(a synchronous custom ESM loader), so the compiled component never touches disk@kamado-io/script-compiler's esbuild dependency to0.28.1(from0.27.4), which fixes a crash in esbuild's IPC channel whenmetafile: trueis combined with a build failure — hit by jsx-compiler's error-path testsDesign notes
module.registerHooks())mainandlayoutget independent compiler instances/caches, sincepage-compiler'sCompilerFunctionnever hands over a file path — seecreateCompileHooksJSDoc for the resolveDir derivation rationalecontentprop regardless oflayouts.contentVariableNamepackages/@kamado-io/jsx-compiler/README.mdfor usage and known constraints (serve-mode memory characteristics, script-compiler extension overlap)Test plan
yarn lintpassesyarn buildpassesyarn testpasses (504 tests, including 37 new jsx-compiler tests: unit, cache, and full build-pipeline integration tests)