diff --git a/packages/language-server/src/html-regions.ts b/packages/language-server/src/html-regions.ts
index 076f8c91..5fb9bd9a 100644
--- a/packages/language-server/src/html-regions.ts
+++ b/packages/language-server/src/html-regions.ts
@@ -100,12 +100,16 @@ export function isInsideHtml(document: TextDocument, offset: number): boolean {
const regionCache = new Map();
function regionsFor(document: TextDocument): HtmlRegion[] {
- const version = document.version ?? -1;
+ // Documents without a version have no way to signal changes, so bypass cache.
+ if (document.version === undefined) {
+ return viewRegions(document.text);
+ }
+
const cached = regionCache.get(document.uri);
- if (cached && cached.version === version) return cached.regions;
+ if (cached && cached.version === document.version) return cached.regions;
const regions = viewRegions(document.text);
- regionCache.set(document.uri, { version, regions });
+ regionCache.set(document.uri, { version: document.version, regions });
return regions;
}
diff --git a/packages/language-server/test/html-regions.test.ts b/packages/language-server/test/html-regions.test.ts
index bf13dd24..78d19be4 100644
--- a/packages/language-server/test/html-regions.test.ts
+++ b/packages/language-server/test/html-regions.test.ts
@@ -107,3 +107,19 @@ test("isInsideHtml distinguishes markup from surrounding code", () => {
expect(isInsideHtml(source, markupOffset)).toBe(true);
expect(isInsideHtml(source, keywordOffset)).toBe(false);
});
+
+test("documents without a version field scan every time and detect mutations", () => {
+ // Without a version, the cache has no key to validate freshness. Mutations
+ // must be detected on every call, even when uri and document are reused.
+ const source = doc(PAGE);
+ // Explicitly verify version is undefined (not set by doc() helper).
+ expect(source.version).toBeUndefined();
+
+ const markupOffset = PAGE.indexOf("