Skip to content

Commit 6c90023

Browse files
committed
fix: unchanged files sometimes have no Angular information for strings when first opened
The `TextStorage` in TS server calls `useScriptVersionCacheIfValidOrOpen` in many places when dealing with a `ScriptInfo`. One of the conditions in that function is to switch to version _if the script is open_. This change in version results in an identity change for the `SourceFile` which is problematic for the compiler because we store references to string literals for inline templates, template URLs, and style URLs. These references will not be valid if the `SourceFile` changed identity. To ensure that the compiler is aware of the change, we mark the project as dirty when a text document is opened. This will cause the project to call `updateGraph`, determine that the file changed versions, and create a new program. This is done so that the Angular compiler can reprocess the file. This also appears to be one of, if not the only issue, that's currently causing the e2e tests to be flaky.
1 parent a876c15 commit 6c90023

File tree

1 file changed

+5
-0
lines changed

1 file changed

+5
-0
lines changed

server/src/session.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -636,6 +636,11 @@ export class Session {
636636
return;
637637
}
638638
if (project.languageServiceEnabled) {
639+
// The act of opening a file can cause the text storage to switchToScriptVersionCache for
640+
// version tracking, which results in an identity change for the source file. We need to
641+
// ensure that the compiler is aware of this and recompiles the file because we store
642+
// references to some string expressions (inline templates, style/template urls).
643+
project.markAsDirty();
639644
// Show initial diagnostics
640645
this.requestDiagnosticsOnOpenOrChangeFile(filePath, `Opening ${filePath}`);
641646
}

0 commit comments

Comments
 (0)