fix(options): isolate startup steps so a throwing step can never kill saving again
Hardening against the 2026-11-25 regression (unguarded JSON.parse of #optionCssFiles="inherit" at global level killed the whole options.js: no handlers bound, Save silently posted stale JSON). run() now executes each startup step through safeStep() (try/catch + console.ls.error) and ALWAYS calls bind(), so the save/change handlers exist even if a prepare step fails. OPTIONS_JS_TOKEN bumped to 20261125.5. Regression guard added in variants/tests/options_save_global.test.js (local-only, gitignored): loads the page with optionCssFiles="inherit" (the global-page condition) and asserts the save button has a click handler, pickers have input+change handlers, a swatch color change reaches the saved options JSON on Save, and the label layout (checkbox box before label; d-block label above btn-groups). Verified the test FAILS on the pre-fix options.js and PASSES on the fixed one; full suite 5/5. Generated by Mistral Vibe. Co-Authored-By: Mistral Vibe <vibe@mistral.ai>
This commit is contained in:
parent
44e0e871d4
commit
7939f3de3f
2 changed files with 32 additions and 14 deletions
|
|
@ -700,29 +700,47 @@ var ThemeOptions = function () {
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
|
// THEME HARDENING: run every startup step isolated — one throwing step must
|
||||||
|
// NEVER prevent bind() (without the save/change handlers, Save silently
|
||||||
|
// posts the stale options JSON; that is exactly the 2026-11-25 regression
|
||||||
|
// where JSON.parse($('#optionCssFiles').val()) threw on "inherit" at global
|
||||||
|
// level and nothing on the page saved anymore).
|
||||||
|
var safeStep = function (name, fn) {
|
||||||
|
try {
|
||||||
|
fn();
|
||||||
|
} catch (e) {
|
||||||
|
if (window.console && console.ls && console.ls.error) {
|
||||||
|
console.ls.error('ThemeOptions step "' + name + '" failed: ' + (e && e.message ? e.message : e));
|
||||||
|
} else if (window.console && console.error) {
|
||||||
|
console.error('ThemeOptions step "' + name + '" failed: ' + (e && e.message ? e.message : e));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
var run = function () {
|
var run = function () {
|
||||||
parseOptionObject();
|
safeStep('parseOptionObject', parseOptionObject);
|
||||||
|
|
||||||
startupGeneralInherit();
|
safeStep('startupGeneralInherit', startupGeneralInherit);
|
||||||
|
|
||||||
prepareSelectField();
|
safeStep('prepareSelectField', prepareSelectField);
|
||||||
prepareTextField();
|
safeStep('prepareTextField', prepareTextField);
|
||||||
parseParentSwitchFields();
|
safeStep('parseParentSwitchFields', parseParentSwitchFields);
|
||||||
prepareCheckboxField();
|
safeStep('prepareCheckboxField', prepareCheckboxField);
|
||||||
prepareFontField();
|
safeStep('prepareFontField', prepareFontField);
|
||||||
prepareFruityThemeField();
|
safeStep('prepareFruityThemeField', prepareFruityThemeField);
|
||||||
showInheritedValue();
|
safeStep('showInheritedValue', showInheritedValue);
|
||||||
|
|
||||||
// THEME ADDITION: font dropdown optgroup order (see above)
|
// THEME ADDITION: font dropdown optgroup order (see above)
|
||||||
reorderFontDropdowns();
|
safeStep('reorderFontDropdowns', reorderFontDropdowns);
|
||||||
|
|
||||||
bind();
|
// ALWAYS bind, even if a prepare step above failed
|
||||||
|
safeStep('bind', bind);
|
||||||
|
|
||||||
// set initial disabled status of child fields
|
// set initial disabled status of child fields
|
||||||
updateAllChildren();
|
safeStep('updateAllChildren', updateAllChildren);
|
||||||
|
|
||||||
// THEME ADDITION: set initial visibility of conditional fields
|
// THEME ADDITION: set initial visibility of conditional fields
|
||||||
updateVisibilityByParent();
|
safeStep('updateVisibilityByParent', updateVisibilityByParent);
|
||||||
};
|
};
|
||||||
|
|
||||||
return run;
|
return run;
|
||||||
|
|
|
||||||
|
|
@ -43,7 +43,7 @@
|
||||||
heuristically cached copy (the file has only Last-Modified/ETag, no Cache-Control).
|
heuristically cached copy (the file has only Last-Modified/ETag, no Cache-Control).
|
||||||
Re-register it with a version token: bump OPTIONS_JS_TOKEN below whenever
|
Re-register it with a version token: bump OPTIONS_JS_TOKEN below whenever
|
||||||
options/options.js changes, so every browser fetches the new file once. #}
|
options/options.js changes, so every browser fetches the new file once. #}
|
||||||
{% set OPTIONS_JS_TOKEN = '20261125.4' %}
|
{% set OPTIONS_JS_TOKEN = '20261125.5' %}
|
||||||
{{ unregisterScriptFile(optionsPath ~ '/options.js') }}
|
{{ unregisterScriptFile(optionsPath ~ '/options.js') }}
|
||||||
{{ registerScriptFile(optionsPath ~ '/options.js?v=' ~ OPTIONS_JS_TOKEN, 'POS_END') }}
|
{{ registerScriptFile(optionsPath ~ '/options.js?v=' ~ OPTIONS_JS_TOKEN, 'POS_END') }}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue