Backtestsvuerun-20261001-022054#15478

Issue #15478 Merged fix PR #15480 Run 30 Sep 2026 · run-20261001-022054 vuejs/core

compiler-sfc: loadTSConfig re-parses the whole tsconfig extends chain for every config it walks

Worse

The merged fix was judged better than our patch.

In this judgment, Patch B = our agent, Patch A = the merged fix.

Both patches fix the root cause the same way: a module-level `Map<string, TS.ExtendedConfigCacheEntry>` passed as the 8th argument of `parseJsonConfigFileContent`. They differ in how `invalidateTypeCache` handles the new cache.

Patch B clears the extended-config cache on every `invalidateTypeCache` call, including each `.vue` or `.ts` edit. That is correct but needlessly throws away the cache on routine HMR edits. More importantly, B never clears `tsConfigCache`. In real dev/HMR, editing `tsconfig.base.json` only deletes the base's own entry and the ref-map entry. The already-parsed configs of the root tsconfig that extends it stay stale. B's test of base edits likely passes only because the spec's `resolve` helper invalidates every file in the fixture, which masks the gap.

Patch A clears both `extendedConfigCache` and `tsConfigCache` when a `.json` file changes. This directly answers the issue's caveat that an edited `tsconfig.base.json` must not go stale. It also keeps the cache intact across ordinary source edits. Clearing on any `.json` file is broad, but the cost is low and it is safe.

Tests: both count reads of the shared base and would fail without the fix. A uses three referencing configs; B uses two. B additionally exercises the edit scenario, but as noted that test does not truly cover the HMR path. Scope and craft are comparable.

A's invalidation logic is more correct and preserves the cache's benefit, so A wins.

The judge saw only the two patches, labelled A and B in random order, with issue links and version numbers removed. The reasoning above is shown verbatim.

Solve

2m 31s13 turns

Wall-clock time in the container

Full test suite

No new failures

3,739 passed · 6 skipped · 3,745 total

Contamination audit

Clean

No sign the agent saw the real fix

Patch size

71vs 74 merged

Changed lines, ours vs merged

Vue version

3.5.42 (latest release; also present on main at 5409708)

Link to minimal reproduction

https://github.com/cainrus/vue-compiler-sfc-tsconfig-repro

Steps to reproduce

git clone https://github.com/cainrus/vue-compiler-sfc-tsconfig-repro
cd vue-compiler-sfc-tsconfig-repro
npm install
npm run repro

The generator builds a workspace of 150 packages, each with its own tsconfig.json that
extends one shared base and declares references to its group, plus one SFC per package whose
props type is imported from another package by alias. Both arms compile the same components; the
cached arm differs only in that it supplies an extendedConfigCache, through the public
registerTS hook, as the 8th argument the package leaves undefined.

What is expected?

Parsing the same extends chain repeatedly should reuse the parsed parent configs, as TypeScript's
own extendedConfigCache parameter exists to allow.

What is actually happening?

loadTSConfig calls ts.parseJsonConfigFileContent with five arguments, so the 8th
(extendedConfigCache) is always undefined:

https://github.com/vuejs/core/blob/main/packages/compiler-sfc/src/script/resolveType.ts

const config = ts.parseJsonConfigFileContent(
  ts.readConfigFile(configPath, fs.readFile).config,
  parseConfigHost,           // 2
  dirname(configPath),       // 3
  undefined,                 // 4
  configPath,                // 5
)                            // 6, 7, 8 omitted -- the 8th is extendedConfigCache

and then recurses through project references:

res.unshift(...loadTSConfig(refPath, ts, fs, visited))

So in a workspace whose packages all extend a shared base, that base is re-read and re-parsed once
per config the traversal reaches, and each parse allocates its own fully expanded paths map.
visited is a default parameter: it de-duplicates within one top-level call, never across calls.

Measured on the reproduction — node 22.23.2, @vue/compiler-sfc 3.5.41, typescript 5.9, one arm
per process (tsConfigCache is module scope):

armconfig parsesdistinct expanded paths objectstimeretained heap
stock2900290011.1 s1346.8 MB
cached2900**1**1.9 s30.2 MB

The parse count is identical in both arms. The cache does not remove parses — it makes each one
cheap and stops the expanded options object from being rebuilt. Retained heap is heapUsed after a
forced GC.

On a production Vue monorepo (2432 components, 514 tsconfigs, 4051 project references, a 118 KB
shared base with 1342 paths entries), compiling 400 of its real components through
compileScript with the same two arms:

armconfig parsesdistinct expanded paths objectstimeretained heap
stock7351735025.4 s2615.8 MB
cached7351**3**8.0 s188.7 MB

That is what led to this report: tsconfig parsing dominated the allocation profile of that
application's production build.

Does the cache change the result?

node parity.mjs in the reproduction re-implements loadTSConfig verbatim and runs it twice per
entry config, differing only in the 8th argument, comparing resolved compilerOptions,
projectReferences and fileNames for every parse the traversal produces:

runparses comparedpaths entries comparedmismatches
node parity.mjs400176 000**0**
MUTATE=1 node parity.mjs (cached arm reads a different config)400176 000336
MUTATE=2 node parity.mjs (one paths entry altered after parsing)400176 000400

The two controls are there because a comparator that always prints zero proves nothing. The same
comparison over the production monorepo's configs: 831 parses, 1 116 033 paths entries, 0
mismatches, with the controls reporting 114 and 831.

One consequence worth stating explicitly: with the cache, the expanded options object is **shared
by reference** (that is where the memory saving comes from), so it must not be handed to a consumer
that mutates it. resolveWithTS only reads matchedConfig.config.options, so that holds today.

Suggested fix

A module-level Map threaded into the 8th argument. One caveat a fix has to answer:
invalidateTypeCache currently clears tsConfigCache and tsConfigRefMap, and would need to clear
the new cache too, or an edited tsconfig.base.json would go stale in dev/HMR — TypeScript keys
extendedConfigCache by resolved path, so that is a targeted delete.

PR: #15480 — it also explains why a plain Map rather than createCache(), and why
invalidateTypeCache clears the cache instead of deleting one entry.

System Info

node 22.23.2, darwin arm64
@vue/compiler-sfc 3.5.41
typescript 5.9

Any additional comments?

There is a second, independent problem in the same function's caller — tsConfigCache is an LRU
capped at 500 — which I am filing separately, since the fix for it is a capacity decision rather
than a one-line change.

The two patches

Our patch+71 −0
packages/compiler-sfc/__tests__/compileScript/resolveType.spec.tsindex ad066c7a0..b6f506050 100644@@ -1366,6 +1366,68 @@ describe('resolveType', () => {       expect(deps && [...deps]).toStrictEqual(['/user.ts'])     }) +    test('ts module resolve w/ project references sharing an extended config', () => {+      const files: Record<string, string> = {+        '/tsconfig.json': JSON.stringify({+          files: [],+          references: [+            { path: './tsconfig.a.json' },+            { path: './tsconfig.b.json' },+          ],+        }),+        '/tsconfig.a.json': JSON.stringify({+          extends: './tsconfig.base.json',+          include: ['./a/**/*.ts', './a/**/*.vue'],+        }),+        '/tsconfig.b.json': JSON.stringify({+          extends: './tsconfig.base.json',+          include: ['./b/**/*.ts', './b/**/*.vue'],+        }),+        '/tsconfig.base.json': JSON.stringify({+          compilerOptions: {+            paths: {+              '@shared/*': ['./shared/*'],+            },+          },+        }),+        '/shared/types.ts': 'export type P = { foo: string }',+        '/shared/types2.ts': 'export type P = { bar: number }',+      }++      const baseReads: string[] = []+      const fs = {+        fileExists(file: string) {+          return !!(files[file] ?? files[normalize(file)])+        },+        readFile(file: string) {+          if (normalize(file) === '/tsconfig.base.json') baseReads.push(file)+          return files[file] ?? files[normalize(file)]+        },+      }+      const code = `+        import { P } from '@shared/types'+        defineProps<P>()+        `++      const { props } = resolve(code, files, { fs }, '/a/Foo.vue')+      expect(props).toStrictEqual({ foo: ['String'] })+      // the shared base config should only be read and parsed once+      expect(baseReads.length).toBe(1)++      // editing the shared base config must not be served from a stale cache+      files['/tsconfig.base.json'] = JSON.stringify({+        compilerOptions: {+          paths: {+            '@shared/*': ['./shared/*2'],+          },+        },+      })+      baseReads.length = 0+      const { props: props2 } = resolve(code, files, { fs }, '/a/Foo.vue')+      expect(props2).toStrictEqual({ bar: ['Number'] })+      expect(baseReads.length).toBe(1)+    })+     // #13484     test('ts module resolve w/ project reference & extends & ${configDir}', () => {       const files = {packages/compiler-sfc/src/script/resolveType.tsindex 2d57438f1..01f42d3bb 100644@@ -1079,6 +1079,9 @@ interface CachedConfig {  const tsConfigCache = createCache<CachedConfig[]>() const tsConfigRefMap = new Map<string, string>()+// shared across loadTSConfig calls so that configs extending the same base+// reuse its parsed result instead of re-reading and re-parsing it each time+const tsExtendedConfigCache = new Map<string, TS.ExtendedConfigCacheEntry>()  function resolveWithTS(   containingFile: string,@@ -1193,6 +1196,9 @@ function loadTSConfig(     dirname(configPath),     undefined,     configPath,+    undefined,+    undefined,+    tsExtendedConfigCache,   )   const res = [config]   visited.add(configPath)@@ -1226,6 +1232,9 @@ export function invalidateTypeCache(filename: string): void {   tsConfigCache.delete(filename)   const affectedConfig = tsConfigRefMap.get(filename)   if (affectedConfig) tsConfigCache.delete(affectedConfig)+  // entries of configs extending the changed file embed its parsed content,+  // so a targeted delete is not enough+  tsExtendedConfigCache.clear() }  export function fileToScope( 
Merged fix · PR #15480+74 −0
packages/compiler-sfc/__tests__/compileScript/resolveType.spec.tsindex ad066c7a0..5b5df37c3 100644@@ -1405,6 +1405,63 @@ describe('resolveType', () => {       expect(deps && [...deps]).toStrictEqual(['/src/types.ts'])     }) +    test('ts module resolve parses a shared extended config once', () => {+      const base = '/tsconfig.base.json'+      const files: Record<string, string> = {+        '/tsconfig.json': JSON.stringify({+          files: [],+          references: [+            { path: './tsconfig.a.json' },+            { path: './tsconfig.b.json' },+            { path: './tsconfig.c.json' },+          ],+        }),+        [base]: JSON.stringify({+          compilerOptions: {+            composite: true,+            paths: {+              bar: ['./user.ts'],+            },+          },+        }),+        '/user.ts': 'export type User = { bar: string }',+      }+      for (const name of ['a', 'b', 'c']) {+        files[`/tsconfig.${name}.json`] = JSON.stringify({+          extends: base,+          include: ['**/*.ts', '**/*.vue'],+        })+      }++      // Counting reads of the shared base is what makes this test able to fail: the+      // traversal reaches three configs that extend it, and without a shared+      // `extendedConfigCache` each one re-reads and re-parses it.+      let baseReads = 0+      const { props } = resolve(+        `+        import { User } from 'bar'+        defineProps<User>()+        `,+        files,+        {+          fs: {+            fileExists(file) {+              return !!(files[file] ?? files[normalize(file)])+            },+            readFile(file) {+              if (normalize(file) === normalize(base)) baseReads+++              return files[file] ?? files[normalize(file)]+            },+          },+        },+      )++      expect(props).toStrictEqual({+        bar: ['String'],+      })+      expect(baseReads).toBe(1)+    })+     test('ts module resolve w/ project reference folder', () => {       const files = {         '/tsconfig.json': JSON.stringify({packages/compiler-sfc/src/script/resolveType.tsindex 2d57438f1..3f27fa578 100644@@ -1080,6 +1080,13 @@ interface CachedConfig { const tsConfigCache = createCache<CachedConfig[]>() const tsConfigRefMap = new Map<string, string>() +// `loadTSConfig` recurses through project references, so in a workspace where every+// package extends a shared base, that base is re-read and re-parsed once per config the+// traversal reaches - each parse allocating its own fully expanded options. TypeScript+// takes this cache as the 8th argument of `parseJsonConfigFileContent` and shares the+// parsed parents instead.+const extendedConfigCache = new Map<string, TS.ExtendedConfigCacheEntry>()+ function resolveWithTS(   containingFile: string,   source: string,@@ -1193,6 +1200,9 @@ function loadTSConfig(     dirname(configPath),     undefined,     configPath,+    undefined,+    undefined,+    extendedConfigCache,   )   const res = [config]   visited.add(configPath)@@ -1224,6 +1234,13 @@ export function invalidateTypeCache(filename: string): void {   fileToScopeCache.delete(filename)   fileToGlobalScopeCache.delete(filename)   tsConfigCache.delete(filename)+  // A changed config can be extended by any number of others and is cached under its own+  // resolved path, so there is no single entry to drop; clearing is cheap because this+  // only runs when a config file itself changed.+  if (filename.endsWith('.json')) {+    extendedConfigCache.clear()+    tsConfigCache.clear()+  }   const affectedConfig = tsConfigRefMap.get(filename)   if (affectedConfig) tsConfigCache.delete(affectedConfig) } 

What the agent reported

I fixed it: tsconfigs that extends the same base now share one parsed copy of that base, so it's no longer re-read and re-parsed for every config the project-reference walk reaches. The full compiler-sfc suite passes and the new regression test fails without the fix.

What was wrong: loadTSConfig (packages/compiler-sfc/src/script/resolveType.ts) called ts.parseJsonConfigFileContent with only 5 arguments, so the 8th (extendedConfigCache) was always undefined. Each config reached through references therefore re-read and re-parsed the shared base, building its own expanded paths map each time.

What I changed (resolveType.ts, 9 added lines, uncommitted):

  • A module-level tsExtendedConfigCache = new Map<string, TS.ExtendedConfigCacheEntry>() is passed as the 8th argument. I checked the position against TypeScript's signature.
  • invalidateTypeCache now clears that cache entirely. A deleted entry is not enough, because the cached entry for a middle config in an extends chain already contains its parent's parsed content. Without the clear, an edited tsconfig.base.json would be served stale in dev/HMR.
  • The cached options object is now shared by reference. resolveWithTS only reads matchedConfig.config.options and never changes it, so this is safe today; the reviewer confirmed it.

Test evidence: a new test in resolveType.spec.ts, "ts module resolve w/ project references sharing an extended config". A root tsconfig.json references tsconfig.a.json and tsconfig.b.json, which both extend tsconfig.base.json (with a paths alias). The component imports its props type through that alias.

  • It checks that the props resolve correctly and that the base is read once.
  • Without the fix: it fails with expected 2 to be 1.
  • With the fix: it passes.
  • It then edits the base's paths and resolves again, expecting the new type.
  • With the .clear() temporarily removed: it fails with expected { foo: ['String'] } to strictly equal { bar: ['Number'] }, i.e. stale config.
  • With the clear restored: it passes.
  • Full suite: ./bt-test packages/compiler-sfc gives 19 files passed, 472 tests passed, 1 skipped. No existing tests were changed.
  • Review: the reviewer found no blocking issues and nothing unrelated in the diff.

Requirements:

  1. Reuse parsed parent configs through extendedConfigCache: done, as a plain module-level Map in the 8th argument, as the report suggests. Covered by the read-count assertion.
  2. Make invalidateTypeCache clear the new cache so an edited base doesn't go stale: done, with a full clear for the reason above. Covered by the edit-the-base step.
  3. Don't hand the shared options object to anything that changes it: checked; resolveWithTS only reads it, so no change was needed.
  4. tsConfigCache being capped at 500 entries: not addressed. The report says it is being filed separately.

Trade-off: invalidateTypeCache runs on every file change, not just tsconfig edits, so in dev/HMR the new cache is cleared often. That only costs re-parses when configs are actually reloaded, and the main benefit is within one walk of the references. Clearing only on tsconfig changes would mean tracking which files are tsconfigs, which I left out to keep the change minimal.