Skip to content

fix(compiler-core): reset pre and v-pre state when parsing starts - #16165

Open
lazerg wants to merge 1 commit into
vuejs:mainfrom
lazerg:fix/issue-16163-parser-reset-state
Open

lazerg wants to merge 1 commit into
vuejs:mainfrom
lazerg:fix/issue-16163-parser-reset-state

Conversation

@lazerg

@lazerg lazerg commented Nov 7, 2026 •

Copy link
Copy Markdown
Contributor

close #16163

If a parse throws while inside a v-pre or <pre> element, the closing tag never runs, so inPre, inVPre and currentVPreBoundary stay set and the next template in the same process gets parsed as if it were still inside them. reset() now clears them, along with the tokenizer's inVPre.

Summary by CodeRabbit

  • Bug Fixes
    • Parsing now correctly handles directives, interpolations, and text whitespace after a previous parse fails, including failures involving duplicate attributes in preformatted content. This prevents stale parser state from affecting subsequent parses.

@coderabbitai

coderabbitai Bot commented Nov 7, 2026 •

Copy link
Copy Markdown

Explain Change →

No actionable comments were generated in the recent review.

Walkthrough

The parser and tokenizer reset methods now clear preformatted-text state after parse errors. Added tests check that later parses process directives, interpolations, and whitespace normally.

Changes: Parse state recovery

Layer / File(s) Summary
Reset preformatted state and verify subsequent parses
packages/compiler-core/src/parser.ts, packages/compiler-core/src/tokenizer.ts, packages/compiler-core/__tests__/parse.spec.ts
Parser reset clears inPre, inVPre, and currentVPreBoundary. Tokenizer reset clears inVPre. Tests check that subsequent parses handle directives and interpolations, and condense whitespace, after duplicate-attribute errors.

Estimated code review effort: 2 (Simple) | ~10 minutes

Change: Bug fix · Severity of issue fixed: Medium

Suggested labels: scope: compiler, :lady_beetle: bug

Suggested reviewers: edison1105

Merge Risk: Minimal · up to 25d85

The change addresses parser state leaking between templates after errors. No merge-blocking concern is identified; merge after normal checks pass.

Pre-merge checks: Passed 5
Check name Status Explanation
Description Check Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check Passed The title "fix(compiler-core): reset pre and v-pre state when parsing starts" matches the main change. The diff resets inPre, inVPre, and currentVPreBoundary in the parser and resets inVPre in the tok…
Linked Issues check Passed Directly linked issue #16163 requires that a parse error inside v-pre or <pre> not leave inVPre, inPre, currentVPreBoundary, or tokenizer inVPre set for later compiles. The diff covers thi…
Out of Scope Changes check Passed All changes relate to the linked issue #16163. The three reset() assignments in parser.ts clear parser state that leaks after an aborted v-pre or <pre> parse. The single line in tokenizer.ts…
Docstring Coverage Passed No eligible functions found in the changed files. Skipping docstring coverage check. Docstring coverage is scoped to functions touched by this diff with cyclomatic complexity of at least 2. Documentat…
Full details: Title check

Explanation

The title "fix(compiler-core): reset pre and v-pre state when parsing starts" matches the main change. The diff resets inPre, inVPre, and currentVPreBoundary in the parser and resets inVPre in the tokenizer before a parse. The linked objectives describe the same fix, so the title is fully related to the changeset.

Full details: Linked Issues check

Explanation

Directly linked issue #16163 requires that a parse error inside v-pre or &lt;pre&gt; not leave inVPre, inPre, currentVPreBoundary, or tokenizer inVPre set for later compiles. The diff covers this. In packages/compiler-core/src/parser.ts, reset() now sets inPre = 0, inVPre = false, and currentVPreBoundary = null. In packages/compiler-core/src/tokenizer.ts, Tokenizer.reset() now sets this.inVPre = false. The new tests in packages/compiler-core/__tests__/parse.spec.ts cover both reported cases. The first parses &lt;div v-pre&gt;&lt;a x x&gt;&lt;/a&gt;&lt;/div&gt;, expects a throw, then expects &lt;p v-if="ok"&gt;{{ x }}&lt;/p&gt; to produce a DIRECTIVE prop and an INTERPOLATION child. The second parses &lt;pre&gt;&lt;a x x&gt;&lt;/a&gt;&lt;/pre&gt; with isPreTag, expects a throw, then expects &lt;div&gt; a b &lt;/div&gt; to condense to ' a b '. Limits of this evidence: the tests were not executed. The inspected file view was truncated, so I could not confirm the call site that invokes tokenizer.reset() on each parse. The issue text states that the parser and tokenizer reset() run before a parse, which supports the chain. No other requirement from #16163 is unmet.

Full details: Out of Scope Changes check

Explanation

All changes relate to the linked issue #16163. The three reset() assignments in parser.ts clear parser state that leaks after an aborted v-pre or &lt;pre&gt; parse. The single line in tokenizer.ts clears the tokenizer flag that the same leak affects. The additions to parse.spec.ts are regression tests for those two cases. No unrelated files or behavior changes appear in the whole-PR diff against the merge base. The diff shows no changes to exported declarations. Limits: the tests were not executed, and the truncated file view did not show every call site, so the link between Tokenizer.reset() and the parse entry point rests on the issue text.

Full details: Docstring Coverage

Explanation

No eligible functions found in the changed files. Skipping docstring coverage check. Docstring coverage is scoped to functions touched by this diff with cyclomatic complexity of at least 2. Documentation-only edits and deletions within surviving functions are included; unchanged diff context and fully deleted functions are excluded. Analyzed 0 functions across 3 files.

Finishing Touches
Generate unit tests (beta)
  • Create a new PR
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

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.

Share
Recent review info
Run configuration
  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: defaults
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 38aaf6a6-c72b-4363-8188-1e5e33460799
Commits

Reviewing files that changed from the base of the PR and between 8b479a8 and 25d8511.

Files selected for processing: 3
  • packages/compiler-core/__tests__/parse.spec.ts
  • packages/compiler-core/src/parser.ts
  • packages/compiler-core/src/tokenizer.ts

Included review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 9 remain after this review.

@pkg-pr-new

pkg-pr-new Bot commented Nov 7, 2026

Copy link
Copy Markdown

Open in StackBlitz

@vue/compiler-core

pnpm add https://pkg.pr.new/@vue/compiler-core@16165
npm i https://pkg.pr.new/@vue/compiler-core@16165
yarn add https://pkg.pr.new/@vue/compiler-core@16165.tgz

@vue/compiler-dom

pnpm add https://pkg.pr.new/@vue/compiler-dom@16165
npm i https://pkg.pr.new/@vue/compiler-dom@16165
yarn add https://pkg.pr.new/@vue/compiler-dom@16165.tgz

@vue/compiler-sfc

pnpm add https://pkg.pr.new/@vue/compiler-sfc@16165
npm i https://pkg.pr.new/@vue/compiler-sfc@16165
yarn add https://pkg.pr.new/@vue/compiler-sfc@16165.tgz

@vue/compiler-ssr

pnpm add https://pkg.pr.new/@vue/compiler-ssr@16165
npm i https://pkg.pr.new/@vue/compiler-ssr@16165
yarn add https://pkg.pr.new/@vue/compiler-ssr@16165.tgz

@vue/reactivity

pnpm add https://pkg.pr.new/@vue/reactivity@16165
npm i https://pkg.pr.new/@vue/reactivity@16165
yarn add https://pkg.pr.new/@vue/reactivity@16165.tgz

@vue/runtime-core

pnpm add https://pkg.pr.new/@vue/runtime-core@16165
npm i https://pkg.pr.new/@vue/runtime-core@16165
yarn add https://pkg.pr.new/@vue/runtime-core@16165.tgz

@vue/runtime-dom

pnpm add https://pkg.pr.new/@vue/runtime-dom@16165
npm i https://pkg.pr.new/@vue/runtime-dom@16165
yarn add https://pkg.pr.new/@vue/runtime-dom@16165.tgz

@vue/server-renderer

pnpm add https://pkg.pr.new/@vue/server-renderer@16165
npm i https://pkg.pr.new/@vue/server-renderer@16165
yarn add https://pkg.pr.new/@vue/server-renderer@16165.tgz

@vue/shared

pnpm add https://pkg.pr.new/@vue/shared@16165
npm i https://pkg.pr.new/@vue/shared@16165
yarn add https://pkg.pr.new/@vue/shared@16165.tgz

vue

pnpm add https://pkg.pr.new/vue@16165
npm i https://pkg.pr.new/vue@16165
yarn add https://pkg.pr.new/vue@16165.tgz

@vue/compat

pnpm add https://pkg.pr.new/@vue/compat@16165
npm i https://pkg.pr.new/@vue/compat@16165
yarn add https://pkg.pr.new/@vue/compat@16165.tgz

commit: 25d8511

@github-actions

github-actions Bot commented Nov 7, 2026

Copy link
Copy Markdown

Size Report

Bundles

File Size Gzip Brotli
runtime-dom.global.prod.js 114 kB 42.7 kB 38.3 kB
vue.global.prod.js 173 kB (+34 B) 63.1 kB (+11 B) 56 kB (+9 B)

Usages

Name Size Gzip Brotli
createApp (CAPI only) 52.7 kB 20.3 kB 18.6 kB
createApp 60.9 kB 23.4 kB 21.4 kB
createSSRApp 65.7 kB 25.4 kB 23.1 kB
defineCustomElement 67.2 kB 25.4 kB 23.1 kB
overall 76.7 kB 29.1 kB 26.4 kB

@edison1105 edison1105 added scope: compiler 🔨 p3-minor-bug Priority 3: this fixes a bug, but is an edge case that only affects very specific usage. ready to merge The PR is ready to be merged. labels Nov 9, 2026

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

🔨 p3-minor-bug Priority 3: this fixes a bug, but is an edge case that only affects very specific usage. ready to merge The PR is ready to be merged. scope: compiler

Projects

None yet

Development

Successfully merging this pull request may close these issues.

compiler-core: parse error inside v-pre or <pre> leaks parser state to later compiles

2 participants