Repository navigation
perf(bundler): add further transform hook filters - #783
Conversation
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: defaults Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (8)
🚧 Files skipped from review as they are similar to previous changes (5)
📝 WalkthroughWalkthroughReplaces substring-based transform gating with regex-driven ChangesTransform Filter Refactor
Estimated code review effort🎯 4 (Complex) | ⏱️ ~45 minutes Possibly related PRs
Poem
🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ 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 |
There was a problem hiding this comment.
Actionable comments posted: 4
🧹 Nitpick comments (2)
packages/bundler/src/unplugin/SSRStaticReplace.ts (1)
6-7: 📐 Maintainability & Code Quality | 🔵 Trivial | 💤 Low valueConsolidate the duplicated
head.ssrpatterns.
HEAD_SSR_FILTER_REandHEAD_SSR_REshare the same source and differ only by thegflag. Keeping two literals risks them drifting if the pattern is ever edited. Consider deriving the global variant from a single source.♻️ Optional consolidation
-const HEAD_SSR_FILTER_RE = /\bhead\.ssr\b/ -const HEAD_SSR_RE = /\bhead\.ssr\b/g +const HEAD_SSR_FILTER_RE = /\bhead\.ssr\b/ +const HEAD_SSR_RE = new RegExp(HEAD_SSR_FILTER_RE.source, 'g')🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@packages/bundler/src/unplugin/SSRStaticReplace.ts` around lines 6 - 7, The two regex constants in SSRStaticReplace duplicate the same `head.ssr` source, so update the module to keep a single source of truth and derive the global variant from it. Refactor the `HEAD_SSR_FILTER_RE` and `HEAD_SSR_RE` definitions so the shared pattern is maintained in one place while preserving the non-global and global behavior used elsewhere in SSRStaticReplace.packages/bundler/src/unplugin/TreeshakeServerComposables.ts (1)
30-61: 📐 Maintainability & Code Quality | 🔵 Trivial | 🏗️ Heavy liftDRY:
shouldTransformId/TRANSFORM_REare near-duplicated across plugins.This
shouldTransformIdbody (andTRANSFORM_RE) is essentially repeated inMinifyTransform.ts(Lines 64-85),UseSeoMetaTransform.ts(Lines 63-86) and here, differing only by theoptions.enabledshort-circuit. Consider extracting a sharedcreateShouldTransformId(options)helper inutils.tsto keep id-eligibility semantics aligned withcreateJsVueTransformIdFilter.🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@packages/bundler/src/unplugin/TreeshakeServerComposables.ts` around lines 30 - 61, The id-eligibility logic in shouldTransformId and the TRANSFORM_RE check are duplicated across TreeshakeServerComposables, MinifyTransform, and UseSeoMetaTransform, with only the options.enabled short-circuit differing. Extract the shared matching behavior into a reusable createShouldTransformId(options) helper in utils.ts, then update shouldTransformId in TreeshakeServerComposables to use it so the semantics stay aligned with createJsVueTransformIdFilter and future changes only need to be made in one place.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@packages/bundler/src/devtools/vite.ts`:
- Line 14: The transform prefilter in vite.ts is out of sync with the
composables list: HEAD_COMPOSABLE_RE currently misses useHeadSafe, so modules
using only that composable never reach the _source injection path. Update the
filter used in the Vite transform logic so it includes useHeadSafe, ideally by
deriving it from HEAD_COMPOSABLES instead of hardcoding the regex, and keep the
check aligned with the composables consumed by the transform.
In `@packages/react/src/stream/plugin.ts`:
- Around line 8-11: The head-composable detection in hasHeadComposable() is
missing useHeadSafe, so React modules using that API are skipped by both the
streaming trigger and codeFilter. Update HEAD_COMPOSABLE_RE in plugin.ts to
include useHeadSafe alongside useHead and useSeoMeta so the transform still runs
and HeadStream injection is applied for those files.
In `@packages/solid-js/src/stream/plugin.ts`:
- Around line 8-12: The head-composable detection regex currently excludes
useHeadSafe, so Solid components using that API are no longer picked up by
hasHeadComposable() or transform.filter.code and skip the streaming transform.
Update the HEAD_COMPOSABLE_RE pattern in plugin.ts to include useHeadSafe again,
and ensure the same shared match logic continues to cover both
hasHeadComposable() and the transform filter so all head composables are
transformed consistently.
In `@packages/svelte/src/stream/plugin.ts`:
- Around line 10-13: The head-composable trigger regex in hasHeadComposable now
misses useHeadSafe, which causes codeFilter to skip files that still need the
transform. Update HEAD_COMPOSABLE_RE so it matches useHeadSafe alongside useHead
and useSeoMeta, and ensure the same trigger is used consistently wherever the
filter/transform decision is made in plugin.ts.
---
Nitpick comments:
In `@packages/bundler/src/unplugin/SSRStaticReplace.ts`:
- Around line 6-7: The two regex constants in SSRStaticReplace duplicate the
same `head.ssr` source, so update the module to keep a single source of truth
and derive the global variant from it. Refactor the `HEAD_SSR_FILTER_RE` and
`HEAD_SSR_RE` definitions so the shared pattern is maintained in one place while
preserving the non-global and global behavior used elsewhere in
SSRStaticReplace.
In `@packages/bundler/src/unplugin/TreeshakeServerComposables.ts`:
- Around line 30-61: The id-eligibility logic in shouldTransformId and the
TRANSFORM_RE check are duplicated across TreeshakeServerComposables,
MinifyTransform, and UseSeoMetaTransform, with only the options.enabled
short-circuit differing. Extract the shared matching behavior into a reusable
createShouldTransformId(options) helper in utils.ts, then update
shouldTransformId in TreeshakeServerComposables to use it so the semantics stay
aligned with createJsVueTransformIdFilter and future changes only need to be
made in one place.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: defaults
Review profile: CHILL
Plan: Pro
Run ID: bc5ec1bc-be2d-4fab-a714-42472c7bce45
📒 Files selected for processing (19)
packages/bundler/src/devtools/vite.tspackages/bundler/src/unplugin/CreateHeadTransform.tspackages/bundler/src/unplugin/MinifyTransform.tspackages/bundler/src/unplugin/SSRStaticReplace.tspackages/bundler/src/unplugin/TreeshakeServerComposables.tspackages/bundler/src/unplugin/UseSeoMetaTransform.tspackages/bundler/src/unplugin/utils.tspackages/bundler/test/createHeadTransform.test.tspackages/bundler/test/minifyTransform.test.tspackages/bundler/test/ssrStaticReplace.test.tspackages/bundler/test/treeshakeServerComposables.test.tspackages/bundler/test/useSeoMetaTransform.test.tspackages/react/src/stream/plugin.tspackages/react/test/vite-plugin.test.tspackages/solid-js/src/stream/plugin.tspackages/solid-js/test/vite-plugin.test.tspackages/svelte/src/stream/plugin.tspackages/svelte/test/vite-plugin.test.tspackages/unhead/src/stream/unplugin.ts
💤 Files with no reviewable changes (4)
- packages/bundler/test/ssrStaticReplace.test.ts
- packages/bundler/test/useSeoMetaTransform.test.ts
- packages/bundler/test/treeshakeServerComposables.test.ts
- packages/bundler/test/minifyTransform.test.ts
❓ Type of change
📚 Description
The branch adds more native
transform.filtergoodies.More
id/codeprefilters across the bundler transforms, Vite-only transforms, and React/Solid/Svelte streaming transforms while keepingtransformIncludefor unplugin adapter compatibility.I have removed the old wrapper helpers, centralizes shared and dropped tests that only asserted filter object shape.
Summary by CodeRabbit
useHeadSafe) are present.head.ssrreplacement transforms for more reliable builds.