fix(compiler-sfc): handle transformed template AST after cache invalidation - #15136
fix(compiler-sfc): handle transformed template AST after cache invalidation#15136edison1105 wants to merge 1 commit into
Conversation
…dation Template usage analysis normally reuses its cached result. Once that cache entry is evicted, a later compileScript() call recomputes the result from the descriptor's template AST. If compileTemplate() has already transformed that AST, walking it again can miss template-only imports and v-model identifiers, notably during a later SSR pass. Reparse transformed template ASTs before analysis, preserving the configured compiler, compiler options, SSR mode, and SFC-relative source locations. Closes #15126 Closes #15128
📝 WalkthroughWalkthroughChangesTemplate analysis flow
Estimated code review effort: 3 (Moderate) | ~20 minutes Sequence Diagram(s)sequenceDiagram
participant compileScript
participant importUsageCheck
participant resolveTemplateAST
participant templateAnalysisCache
compileScript->>importUsageCheck: analyze template with template options
importUsageCheck->>templateAnalysisCache: read or write analysis result
importUsageCheck->>resolveTemplateAST: resolve transformed AST
resolveTemplateAST-->>importUsageCheck: rooted template AST
importUsageCheck-->>compileScript: used imports and v-model identifiers
Possibly related PRs
Suggested labels: 🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
Warning There were issues while running some tools. Please review the errors and either fix the tool's configuration or disable the tool if it's a critical failure. 🔧 ESLint
ESLint install timed out. The project may have too many dependencies for the sandbox. Comment |
@vue/compiler-core
@vue/compiler-dom
@vue/compiler-sfc
@vue/compiler-ssr
@vue/reactivity
@vue/runtime-core
@vue/runtime-dom
@vue/server-renderer
@vue/shared
vue
@vue/compat
commit: |
Size ReportBundles
Usages
|
There was a problem hiding this comment.
Caution
Some comments are outside the diff and can’t be posted inline due to platform limitations.
⚠️ Outside diff range comments (1)
packages/compiler-sfc/src/script/importUsageCheck.ts (1)
59-86: 🎯 Functional Correctness | 🟠 Major | ⚡ Quick winKey cached analysis by its parsing context.
At Line 68, the cache uses only
content, although the new result depends oncompiler,compilerOptions, andssr. A transformed shared descriptor analyzed under one delimiter/compiler setting can return staleusedIdsorvModelIdsduring a later pass with different options, again omitting returned imports or v-model demotion. Include parse context in cache validation/keying, or bypass this content-only cache for transformed ASTs.🤖 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/compiler-sfc/src/script/importUsageCheck.ts` around lines 59 - 86, Update resolveTemplateAnalysisResult so templateAnalysisCache entries are keyed and validated by the parsing context, including options.compiler, options.compilerOptions, and options.ssr, in addition to template content. Ensure analyses from transformed descriptors or differing compiler settings cannot reuse stale usedIds or vModelIds; alternatively bypass the cache for transformed ASTs while preserving reuse for compatible contexts.
🤖 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.
Outside diff comments:
In `@packages/compiler-sfc/src/script/importUsageCheck.ts`:
- Around line 59-86: Update resolveTemplateAnalysisResult so
templateAnalysisCache entries are keyed and validated by the parsing context,
including options.compiler, options.compilerOptions, and options.ssr, in
addition to template content. Ensure analyses from transformed descriptors or
differing compiler settings cannot reuse stale usedIds or vModelIds;
alternatively bypass the cache for transformed ASTs while preserving reuse for
compatible contexts.
ℹ️ Review info
⚙️ Run configuration
Configuration used: defaults
Review profile: CHILL
Plan: Pro
Run ID: 52fb116e-ea9c-4a00-a0ce-22dde73dfb96
📒 Files selected for processing (5)
packages/compiler-sfc/__tests__/compileScript.spec.tspackages/compiler-sfc/src/compileScript.tspackages/compiler-sfc/src/compileTemplate.tspackages/compiler-sfc/src/script/importUsageCheck.tspackages/compiler-sfc/src/template/resolveTemplateAST.ts
|
/ecosystem-ci run |
|
📝 Ran ecosystem CI: Open
|
Template usage analysis normally reuses its cached result. Once that cache entry is evicted, a later compileScript() call recomputes the result from the descriptor's template AST.
If compileTemplate() has already transformed that AST, walking it again can miss template-only imports and v-model identifiers, notably during a later SSR pass.
Reparse transformed template ASTs before analysis, preserving the configured compiler, compiler options, SSR mode, and SFC-relative source locations.
Closes #15126
Closes #15128
Summary by CodeRabbit
Bug Fixes
v-modeldetection based on configured template options.Tests