Skip to content

Commit 39304f1

Browse files
Tyriareli-w-king
authored andcommitted
Merge pull request #286840 from microsoft/copilot/sub-pr-286838
Clear CSS cache on theme change to prevent stale CSS variable values
2 parents e1f9493 + 37953c4 commit 39304f1

File tree

2 files changed

+17
-0
lines changed

2 files changed

+17
-0
lines changed

src/vs/editor/browser/gpu/css/decorationCssRuleExtractor.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,4 +96,13 @@ export class DecorationCssRuleExtractor extends Disposable {
9696
}
9797
return result;
9898
}
99+
100+
/**
101+
* Clears all cached CSS rules and CSS variable values. This should be called when the theme
102+
* changes to ensure fresh values are computed.
103+
*/
104+
clear(): void {
105+
this._ruleCache.clear();
106+
this._cssVariableCache.clear();
107+
}
99108
}

src/vs/editor/browser/gpu/viewGpuContext.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ import { IInstantiationService } from '../../../platform/instantiation/common/in
1616
import { TextureAtlas } from './atlas/textureAtlas.js';
1717
import { IConfigurationService } from '../../../platform/configuration/common/configuration.js';
1818
import { INotificationService, IPromptChoice, Severity } from '../../../platform/notification/common/notification.js';
19+
import { IThemeService } from '../../../platform/theme/common/themeService.js';
1920
import { GPULifecycle } from './gpuDisposable.js';
2021
import { ensureNonNullable, observeDevicePixelDimensions } from './gpuUtils.js';
2122
import { RectangleRenderer } from './rectangleRenderer.js';
@@ -82,6 +83,7 @@ export class ViewGpuContext extends Disposable {
8283
@IInstantiationService private readonly _instantiationService: IInstantiationService,
8384
@INotificationService private readonly _notificationService: INotificationService,
8485
@IConfigurationService private readonly configurationService: IConfigurationService,
86+
@IThemeService private readonly _themeService: IThemeService,
8587
) {
8688
super();
8789

@@ -124,6 +126,12 @@ export class ViewGpuContext extends Disposable {
124126
this.devicePixelRatio = dprObs;
125127
this._register(runOnChange(this.devicePixelRatio, () => ViewGpuContext.atlas?.clear()));
126128

129+
// Clear decoration CSS caches when theme changes as CSS variables may have different values
130+
this._register(this._themeService.onDidColorThemeChange(() => {
131+
ViewGpuContext.decorationCssRuleExtractor.clear();
132+
ViewGpuContext.atlas?.clear();
133+
}));
134+
127135
const canvasDevicePixelDimensions = observableValue(this, { width: this.canvas.domNode.width, height: this.canvas.domNode.height });
128136
this._register(observeDevicePixelDimensions(
129137
this.canvas.domNode,

0 commit comments

Comments
 (0)