Repository navigation
perf(bundler): unify AST transforms into one parse/walk pipeline - #831
Merged
harlan-zw merged 5 commits intoJul 14, 2026
Merged
Conversation
TreeshakeServerComposables, UseSeoMetaTransform and MinifyTransform each ran their own oxc parseSync + oxc-walker walk + MagicString over the same modules, so a module matching all three code filters parsed three times per build. The new private createTransformPipeline runs all three concerns over a single parse, ScopeTracker walk, MagicString and sourcemap: - rolldown-first filtering: the unified plugin's transform.filter uses the union code regex and the shared JS/Vue id filter so rolldown/Vite skip the JS hook natively; cheap per-concern regexes re-gate phases inside the handler - phase order per call site is preserved: treeshake claims removed statement ranges first, and the seoMeta/minify phases skip any node inside a claimed range (previously guaranteed by plugin registration order) - per-target dispatch stays per transform call via resolveBuildConsumer; unknown targets retain server code, sharedDuringBuild stays on - overlapping edits from two phases are detected up front and throw one contextual error (file + offsets) with no partial output - parser failures return undefined (no transform), matching the previous MinifyTransform behavior - the treeshake provenance check accepts importPaths, defaulting to the seoMeta importPaths inside the unified pipeline The public factories (TreeshakeServerComposables, UseSeoMetaTransform, MinifyTransform) remain exported as thin single-concern adapters over the pipeline; Unhead()/createFrameworkPlugin() now register one plugin. Combined transform-positive module: 375 -> 745 ops/s (~2.0x); prefiltered unrelated module: 333k -> 539k ops/s (no regression).
|
Important Review skippedAuto reviews are disabled on base/target branches other than the default branch. Please check the settings in the CodeRabbit UI or the ⚙️ Run configurationConfiguration used: defaults Review profile: CHILL Plan: Pro Run ID: You can disable this status message by setting the Use the checkbox below for a quick retry:
✨ Finishing Touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
This was referenced Jul 13, 2026
Replace the string-only nested-object decoder with a safe recursive AST value decoder (string/number/boolean/null literals, unary +/- on numeric literals, expression-free template literals, arrays and plain objects with static keys; everything else returns a bail sentinel). Nested robots-style objects with numbers, negative numbers and booleans now compile. Match runtime `unpackMeta` exactly for the lowered output: - replicate `sanitizeObject` (top-level entries stringifying to 'false' are dropped before packing) - render structural expansions (media objects/arrays, array values) before scalar/packed props, mirroring `[...extras, ...meta]` - hoist `url`/`secureUrl` first inside media object expansions - bail arrayable meta keys (themeColor, ...) whose objects route through `handleObjectEntry` at runtime - emit `'http-equiv'` quoted (was previously invalid JS output) Add a per-prop residual fallback: when a value-level failure occurs, the unsupported tail is kept on the original composable adjacent to the lowered call, but only when provably render-identical (statement position, no options arg, no title after the failure point, disjoint resolved meta names, and residual props primitives-routed unless nothing was lowered). Verified by a runtime-vs-compiled equivalence corpus (37 fixtures rendered through the real unhead server runtime from both the original call and the transformed output) doubling as an eligibility floor so future changes can't silently narrow supported input.
… into feat/unified-transform-pipeline
… into feat/unified-transform-pipeline
… into feat/unified-transform-pipeline # Conflicts: # packages/bundler/src/unplugin/TreeshakeServerComposables.ts # packages/bundler/src/unplugin/UseSeoMetaTransform.ts
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.
Stacks on #829 (
fix/bundler-transform-targeting).🔗 Linked issue
N/A
❓ Type of change
📚 Description
What
TreeshakeServerComposables,UseSeoMetaTransformandMinifyTransformeach ran their ownparseSync(oxc-parser) +oxc-walkerwalk +MagicString+ sourcemap over the same modules, with duplicatedshouldTransformId/shouldTransformCode. A module matching all three code filters parsed three times per build.This merges the three concerns into one private
createTransformPipelinemodule (src/unplugin/createTransformPipeline.ts, not exported from any public entry): one combined prefilter, one parse, oneScopeTrackerwalk dispatching per node to the three concerns, oneMagicString, one sourcemap.Architecture
transform.filteruses the union code regex (SEO_META_RE | SERVER_COMPOSABLE_RE | HEAD_REsources joined) and the sharedcreateJsVueTransformIdFilterid filter, so rolldown/Vite run these natively and skip the JS hook. Inside the handler, cheap per-concern regex + id checks decide which phases run (per-concernfilter.include/excludeoverrides still apply per phase).transformIncludeis kept for webpack/rspack.ExpressionStatementrange; the seoMeta and minify phases skip any node inside a claimed range. This reproduces what plugin registration order used to guarantee (auseServerSeoMetacall treeshaken from the client build is never seoMeta-rewritten or minified — the differential test asserts the minifier is not even invoked for removed nodes). Then seoMeta lowering, then static content minify (still async: pending minifications are collected during the walk and awaited after).resolveBuildConsumer(...) === 'client'; seoMeta + minify run for both; unknown targets retain server code.sharedDuringBuild: trueand thevite.apply()/webpack()fallbacks are preserved; onservethe pipeline still installs for the seoMeta/minify concerns but hard-disables the treeshake phase (and returnsfalsefromapplywhen treeshake is the only concern, matching the old plugin).undefined(no transform), matching the previousMinifyTransformbehavior.Unhead()/createFrameworkPlugin()keep their interfaces and options (treeshake,transformSeoMeta,minify,filter,imports,importPaths, ...);resolveCoreDefscollapses to a single def wiring the pipeline.TreeshakeServerComposables,UseSeoMetaTransformandMinifyTransformremain exported and functional as thin single-concern adapters constructing the same pipeline. Export snapshots pass unchanged.SSRStaticReplaceandCreateHeadTransformare untouched.Performance (same machine,
vitest bench bench/unplugin-transform.bench.ts)Base branch numbers measured with the pristine base plugin sources.
New bench cases (
combined module/prefiltered module, three-pass vs unified) are committed inbench/unplugin-transform.bench.ts.Tests
test/exports.test.ts --pool=threads), full repo suite (1622 tests) and lint.packages/bundler/test/transformPipeline.test.ts:Consolidation notes
importPathsthreading (done):TreeshakeServerComposablesOptionsnow acceptsimportPaths; inside the unified pipeline the treeshake provenance check defaults to the seoMetaimportPaths, so e.g.transformSeoMeta: { importPaths: ['#imports'] }also lets treeshake proveimport { useServerHead } from '#imports'removable. The standaloneTreeshakeServerComposablesadapter only uses its own option, so default behavior is unchanged.@unhead/bundler/minify/rolldownvs.../esbuild(skipped): would require dynamic imports insideresolveCoreDefs(the minifier subpaths pull optional peer deps), which didn't fall out naturally; noting per task.