Skip to content
TypeScript

fix(web): preserve theme when toggling advanced colors (#8500)

Wout Stiens0222aa255d11
diff --git a/apps/web/src/components/settings/ThemeEditorPanel.tsx b/apps/web/src/components/settings/ThemeEditorPanel.tsx
index 0bb0d1b0ec1..9ac264cd00d 100644
--- a/apps/web/src/components/settings/ThemeEditorPanel.tsx
+++ b/apps/web/src/components/settings/ThemeEditorPanel.tsx
@@ -308,6 +308,7 @@ export function ThemeEditorPanel({
const [simpleColorsDirtyByAppearance, setSimpleColorsDirtyByAppearance] = useState<
Record<ThemeAppearance, boolean>
>({ light: false, dark: false });
+ const [shouldRegenerateGuidedColors, setShouldRegenerateGuidedColors] = useState(false);
const [error, setError] = useState<string | null>(null);
const [isMinimized, setIsMinimized] = useState(false);
const [roleQuery, setRoleQuery] = useState("");
@@ -401,6 +402,10 @@ export function ThemeEditorPanel({
// regenerate when the guided editor produced it.
setIsAdvanced(sourceTheme !== null && sourceTheme.managed !== true);
setSimpleColorsDirtyByAppearance({ light: false, dark: false });
+ // An unmanaged palette needs conversion when the user opts into the
+ // guided editor. Merely revealing Advanced for a managed/default draft
+ // must stay read-only until a color changes.
+ setShouldRegenerateGuidedColors(sourceTheme !== null && sourceTheme.managed !== true);
setColorsByAppearance(nextColors);
setSelectedRole(null);
setUsageCount(null);
@@ -497,6 +502,7 @@ export function ThemeEditorPanel({
[activeAppearance]: true,
}));
}
+ if (isAdvanced) setShouldRegenerateGuidedColors(true);
},
[activeAppearance, isAdvanced],
);
@@ -735,6 +741,7 @@ export function ThemeEditorPanel({
if (selectedRole && !THEME_EDITOR_SIMPLE_ROLES.includes(selectedRole)) {
setSelectedRole(null);
}
+ if (!shouldRegenerateGuidedColors) return;
// Regenerate every appearance the theme will save, not just the visible
// one, so the palettes shown after toggling match what gets saved.
@@ -754,8 +761,9 @@ export function ThemeEditorPanel({
}
return next;
});
+ setShouldRegenerateGuidedColors(false);
},
- [activeAppearance, editingTheme, selectedRole],
+ [activeAppearance, editingTheme, selectedRole, shouldRegenerateGuidedColors],
);
const handleSubmit = () => {