fix(SettingsDialog): race condition in SettingsDialog causing settings to be unexpectedly cleared (#10875)

Co-authored-by: Gal Zahavi <38544478+galz10@users.noreply.github.com>
Co-authored-by: Jacob Richman <jacob314@gmail.com>
This commit is contained in:
lifefloating
2025-10-21 01:37:56 +08:00
committed by GitHub
parent 35afab31e1
commit d0ab6e9982
2 changed files with 240 additions and 69 deletions
@@ -153,18 +153,15 @@ export function SettingsDialog({
);
}
setPendingSettings((prev) =>
setPendingSettingValue(key, newValue as boolean, prev),
);
if (!requiresRestart(key)) {
const immediateSettings = new Set([key]);
const currentScopeSettings =
settings.forScope(selectedScope).settings;
const immediateSettingsObject = setPendingSettingValueAny(
key,
newValue,
{} as Settings,
currentScopeSettings,
);
console.log(
`[DEBUG SettingsDialog] Saving ${key} immediately with value:`,
newValue,
@@ -205,11 +202,6 @@ export function SettingsDialog({
next.delete(key);
return next;
});
// Refresh pending settings from the saved state
setPendingSettings(
structuredClone(settings.forScope(selectedScope).settings),
);
} else {
// For restart-required settings, track as modified
setModifiedSettings((prev) => {
@@ -299,10 +291,11 @@ export function SettingsDialog({
if (!requiresRestart(key)) {
const immediateSettings = new Set([key]);
const currentScopeSettings = settings.forScope(selectedScope).settings;
const immediateSettingsObject = setPendingSettingValueAny(
key,
parsed,
{} as Settings,
currentScopeSettings,
);
saveModifiedSettings(
immediateSettings,
@@ -658,14 +651,16 @@ export function SettingsDialog({
typeof defaultValue === 'string'
? defaultValue
: undefined;
const currentScopeSettings =
settings.forScope(selectedScope).settings;
const immediateSettingsObject =
toSaveValue !== undefined
? setPendingSettingValueAny(
currentSetting.value,
toSaveValue,
{} as Settings,
currentScopeSettings,
)
: ({} as Settings);
: currentScopeSettings;
saveModifiedSettings(
immediateSettings,