From 9431df3f90afad34423d353360e673d7baf1e7b7 Mon Sep 17 00:00:00 2001 From: Elia Schito Date: Mon, 16 Mar 2026 17:20:31 +0100 Subject: [PATCH] Skip non-theme directories when preloading files Restrict preload() to Shopify theme directories (assets, blocks, config, layout, locales, sections, snippets, templates). Previously all .json files under the root were loaded, including unrelated data files. A single 175 MB JSON file parsed into an AST can consume 1-2 GB of heap, easily exhausting even an 8 GB limit on large repos. Co-Authored-By: Claude --- .../src/documents/DocumentManager.ts | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/packages/theme-language-server-common/src/documents/DocumentManager.ts b/packages/theme-language-server-common/src/documents/DocumentManager.ts index 6102b6e25..39b47bafa 100644 --- a/packages/theme-language-server-common/src/documents/DocumentManager.ts +++ b/packages/theme-language-server-common/src/documents/DocumentManager.ts @@ -133,10 +133,18 @@ export class DocumentManager { // We'll only load the files that aren't already in the store. No need to // parse a file we already parsed. + // + // NOTE: We restrict to Shopify theme directories to avoid loading large + // data files (e.g. data/*.json) that are not part of the theme itself. + // A 175MB JSON file parsed into an AST can easily consume 1–2 GB of heap. + const THEME_DIRS = /\/(assets|blocks|config|layout|locales|sections|snippets|templates)\//; const filesToLoad = await recursiveReadDirectory( this.fs, rootUri, - ([uri]) => /\.(liquid|json)$/.test(uri) && !this.sourceCodes.has(uri), + ([uri]) => + /\.(liquid|json)$/.test(uri) && + THEME_DIRS.test(uri) && + !this.sourceCodes.has(uri), ); progress.report(10, 'Preloading files');