Compare commits

...
Author SHA1 Message Date
l0ng-ai d4ca3d7857 fix(plugins): keep the applied plugin theme over an older plugin list
refreshPlugins' generation guard drops a list answered after a newer refresh, but not
one answered after a themeChanged event. Opening a project refreshes the list while the
plugin theme is being re-applied: the event set One Dark Vivid Islands, then the earlier
list arrived without an active theme and the editor fell back to the built-in dark
theme while the menu still showed the plugin theme checked. Theme events and theme
choices now go through setActivePluginTheme, which stamps them; a list requested before
the latest stamp keeps the current active theme.

Fixes #5793
2026-11-25 15:42:19 +08:00
4 changed files with 47 additions and 9 deletions

No files matched your search

@@ -385,6 +385,26 @@ describe("store", () => {
expect(usePlugins.getState().activeTheme).toBeNull();
});
it("keeps a theme applied by an event over an older plugin list that predates it", async () => {
await refreshPlugins();
const applied = await backend.setTheme("theme-harbor-night", "harbor-night");
await backend.setTheme(null, null);
// The list is read before the theme lands and answers after its event.
let release!: () => void;
const gate = new Promise<void>((r) => (release = r));
const stale = await backend.list();
setPluginsBackend({ ...backend, list: () => gate.then(() => stale) });
const refresh = refreshPlugins();
handlePluginEvent({ type: "themeChanged", theme: applied });
release();
await refresh;
expect(usePlugins.getState().activeTheme?.theme.id).toBe("harbor-night");
// A list requested after the event is taken as it is.
setPluginsBackend(backend);
await refreshPlugins();
expect(usePlugins.getState().activeTheme).toBeNull();
});
it("applies the plugin theme the Appearance setting selects, and clears it for a built-in one", async () => {
const stop = [syncProjection(), followThemeSetting()];
try {
+9 -2
View File
@@ -18,7 +18,14 @@ import { pluginsBackend } from "./backend";
import { trackIconTheme } from "./iconThemes";
import { defineBuiltinUiPoints } from "./points";
import { handleRuntimeEvent, refreshEventKinds, startRuntimeUi } from "./runtimeUi";
import { grantPlugin, runPluginCommand, refreshPlugins, updateAllPlugins, usePlugins } from "./store";
import {
grantPlugin,
runPluginCommand,
refreshPlugins,
setActivePluginTheme,
updateAllPlugins,
usePlugins,
} from "./store";
import { followThemeSetting, syncPluginProjection, trackPluginTheme } from "./themeRuntime";
export { pluginActionId } from "./points";
@@ -94,7 +101,7 @@ export function handlePluginEvent(e: PluginEvent) {
break;
}
case "themeChanged":
usePlugins.setState({ activeTheme: e.theme });
setActivePluginTheme(e.theme);
break;
case "consentRequested":
void refreshPlugins().then(() => grantPlugin(e.pluginId, e.capabilities));
+2 -2
View File
@@ -15,7 +15,7 @@ import { useIntellijThemesDialog } from "./intellijThemesDialogStore";
import { defineUiPoint } from "./projection";
import { refreshRunTargets, startRunTargets } from "./runTargets";
import { projectSettings, type SettingsDecl } from "./settings";
import { refreshPlugins, SETTINGS_PAGE_ID, usePlugins } from "./store";
import { refreshPlugins, setActivePluginTheme, SETTINGS_PAGE_ID } from "./store";
import { syncPluginProjection, trackPluginTheme } from "./themeRuntime";
export function registerPluginsPage(): () => void {
@@ -92,7 +92,7 @@ function followSettingsPluginChanges(): () => void {
}
break;
case "themeChanged":
usePlugins.setState({ activeTheme: e.theme });
setActivePluginTheme(e.theme);
break;
case "languagesChanged":
languageListChanged();
+16 -5
View File
@@ -102,21 +102,33 @@ function askConsent(req: ConsentRequest): Promise<Consent | null> {
// --- loading ------------------------------------------------------------------
let generation = 0;
/** Bumped whenever the active theme arrives on its own (a theme event, a theme choice). */
let themeStamp = 0;
/**
* Sets the active plugin theme from a `themeChanged` event or a theme choice. A plugin list
* requested before it carries the older theme, so its snapshot no longer overrides this one.
*/
export function setActivePluginTheme(activeTheme: ActiveTheme | null) {
themeStamp++;
usePlugins.setState({ activeTheme });
}
export async function refreshPlugins(): Promise<void> {
const gen = ++generation;
const stamp = themeStamp;
usePlugins.setState({ loading: true });
try {
const snapshot = await pluginsBackend().list();
if (gen !== generation) return;
usePlugins.setState({
usePlugins.setState((s) => ({
plugins: snapshot.plugins,
ui: snapshot.ui,
activeTheme: snapshot.activeTheme,
activeTheme: stamp === themeStamp ? snapshot.activeTheme : s.activeTheme,
loaded: true,
loading: false,
error: null,
});
}));
} catch (e) {
if (gen !== generation) return;
usePlugins.setState({ loading: false, loaded: true, error: errorText(e) });
@@ -383,8 +395,7 @@ export async function installFromDisk(
export async function selectPluginTheme(pluginId: string | null, themeId: string | null): Promise<void> {
try {
const activeTheme = await pluginsBackend().setTheme(pluginId, themeId);
usePlugins.setState({ activeTheme });
setActivePluginTheme(await pluginsBackend().setTheme(pluginId, themeId));
} catch (e) {
notifications().notify({ group: "plugins", level: "error", title: "Could not apply theme", body: errorText(e) });
}