Repository navigation
perf(bundler): broaden static useSeoMeta lowering - #834
Merged
harlan-zw merged 1 commit intoJul 14, 2026
Merged
Conversation
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.
|
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 |
harlan-zw
added a commit
that referenced
this pull request
Jul 14, 2026
* perf(bundler): unify AST transforms into one parse/walk pipeline 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). * perf(bundler): broaden static useSeoMeta lowering (#834) 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.
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 #831 (
feat/unified-transform-pipeline).What
Broadens the static
useSeoMeta/useServerSeoMetalowering in the unified transform pipeline and closes the runtime-parity gaps it exposed.Safe recursive AST-value decoder
materializeStaticStringObject's string-only value decoder is replaced withdecodeStaticValue, supporting exactly:nullliterals-/+on numeric literals (-1,+1.5)Object.create(null)Always rejected via a sentinel (never throws): spreads, computed keys, getters/setters/methods (
kind !== 'init'),__proto__/constructor/prototypekeys, identifiers/calls/member expressions, regexp/bigint literals, array holes, anything else.robots: { maxSnippet: -1, maxImagePreview: 'large', noindex: false }now lowers instead of forfeiting the whole call.Runtime parity fixes (verified against
unpackMeta)The equivalence suite (below) exposed places where the existing lowering diverged from runtime rendering; these are fixed so compiled output is byte-identical to what runtime produces:
sanitizeObjectsemantics: runtime drops top-level packed-object entries whose value stringifies to'false'before packing; the transform now replicates this (noindex: falsedisappears, matching runtime).[...extras, ...meta]ordering: runtime renders structural expansions (media objects/arrays, array values) before scalar/packed props regardless of source order. Lowered meta lines are now grouped the same way (previously{ description, ogImage: {…} }compiled to source order but rendered media-first at runtime).url/secureUrl-first inside static media object expansions (runtime hoists them); array elements hoist onlyurl, matching the runtime array branch.themeColor,author,googleSiteVerification) with object values now bail to runtime:unpackMetaroutes them throughhandleObjectEntry(sibling tags), notresolvePackedMetaObjectValue(packed string), so the old lowering produced wrong content for them.http-equivemission: previously emitted{ http-equiv: … }, which is invalid JS (anycontentType/refresh/contentSecurityPolicylowering produced unparseable output). Now quoted.Per-prop residual fallback (done, tightly guarded)
On a value-level failure (dynamic media value, undecodable nested object), the unsupported tail is now kept on the original composable adjacent to the lowered call:
This creates a second head entry, so it is only emitted when provably render-identical:
title/titleTemplatenever appear after the failure point (they are hoisted regardless of position; last-wins order would change)key: valuepairs whose resolved meta names are disjoint from the lowered props' names (a shared name, e.g.ogImageUrl+ogImage->og:image, would dedupe across entries and reorder tags -> whole-call bail, tested)meta(failedAt === 0, the issue Unable to resolve dynamicogImageobject value #769{ title, ogImage: ref }shape). A dynamic media value after lowered scalar props stays a whole-call bail: at runtime it could resolve to an object and render before the lowered props (extrasordering), which a trailing residual entry cannot reproduce — covered by an explicit bail fixture.MEDIA_KEYS dynamic-value bail rules are unchanged; the residual mechanism only relocates already-bailing props, it never lowers them.
Tests
seoMetaRuntimeEquivalence.test.ts): 37 fixtures rendered through the real unhead server runtime twice — once from the originaluseSeoMetacall, once from the transformed output — asserting identicalheadTags, including overlapping-dedupe and ordering cases.Bundle evidence
bench/bundlestatic-SEO fixtures rebuilt on base (096f0de9) and this branch — byte-identical, the saving holds exactly (the fixture is all flat keys, unaffected by the broadened decoder):Saving: 22.3% gzip (unchanged).
last.jsonuntouched.Notes
__proto__/constructor/prototypekeys inside packed meta objects — they are only serialized into a content string viaObject.entries(no object writes), andnormalizePropsalready skips unsafe keys on tag props, so there is no runtime pollution path. The transform rejects them at decode time so it never materializes such objects at build time; no runtime behavior was added.robots: someRef) still inline ascontentand would render[object Object]if they resolve to an object at runtime (same class of problem as Unable to resolve dynamicogImageobject value #769 but for packed keys); the runtime array-branchsecureUrlcolon-casing quirk (og:image:secure:url) is not replicated.pnpm typecheckfails on base with a pre-existing error inpackages/bundler/test/fixtures/vite-build/entry.ts(unrelated to this change).