From 7939f3de3f212273d96955762a643ffda2edeb54 Mon Sep 17 00:00:00 2001 From: Tammo ter Hark Date: Wed, 25 Nov 2026 21:28:43 +0100 Subject: [PATCH] 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 --- options/options.js | 44 +++++++++++++++++++++++++++++++------------- options/options.twig | 2 +- 2 files changed, 32 insertions(+), 14 deletions(-) diff --git a/options/options.js b/options/options.js index b90b6cc..6c1b7d3 100644 --- a/options/options.js +++ b/options/options.js @@ -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 () { - parseOptionObject(); + safeStep('parseOptionObject', parseOptionObject); - startupGeneralInherit(); + safeStep('startupGeneralInherit', startupGeneralInherit); - prepareSelectField(); - prepareTextField(); - parseParentSwitchFields(); - prepareCheckboxField(); - prepareFontField(); - prepareFruityThemeField(); - showInheritedValue(); + safeStep('prepareSelectField', prepareSelectField); + safeStep('prepareTextField', prepareTextField); + safeStep('parseParentSwitchFields', parseParentSwitchFields); + safeStep('prepareCheckboxField', prepareCheckboxField); + safeStep('prepareFontField', prepareFontField); + safeStep('prepareFruityThemeField', prepareFruityThemeField); + safeStep('showInheritedValue', showInheritedValue); // 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 - updateAllChildren(); + safeStep('updateAllChildren', updateAllChildren); // THEME ADDITION: set initial visibility of conditional fields - updateVisibilityByParent(); + safeStep('updateVisibilityByParent', updateVisibilityByParent); }; return run; diff --git a/options/options.twig b/options/options.twig index 65ed7b6..dbaa6c7 100644 --- a/options/options.twig +++ b/options/options.twig @@ -43,7 +43,7 @@ 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 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') }} {{ registerScriptFile(optionsPath ~ '/options.js?v=' ~ OPTIONS_JS_TOKEN, 'POS_END') }}