Fix ?reset=1 when #reset=1 is added to an already-open page (Refs #19)

The flag was read once at load, but editing only the fragment fires
hashchange instead of reloading. Read it on each render and re-render
on hashchange.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
2026-11-23 21:30:44 -05:00
parent 60501b9508
commit 6048398c1e
2 changed files with 5 additions and 3 deletions

View File

@@ -21,7 +21,8 @@
}; };
// ?reset=1 (or #reset=1): after unlock, offer to erase every secret value. // ?reset=1 (or #reset=1): after unlock, offer to erase every secret value.
const resetRequested = /[?#&]reset=1(?![0-9])/.test(location.search + location.hash); // Read live: typing #reset=1 into an already-open page only fires hashchange, it does not reload.
const resetRequested = () => /[?#&]reset=1(?![0-9])/.test(location.search + location.hash);
const resetBanner = () => { const resetBanner = () => {
const n = countSecrets(state.doc); const n = countSecrets(state.doc);
const done = () => { state.resetOffered = true; render(); }; const done = () => { state.resetOffered = true; render(); };
@@ -792,12 +793,13 @@
btn('Change passphrase', changePassphrase), btn('Change passphrase', changePassphrase),
btn('Print…', openPrintDialog), btn('Print…', openPrintDialog),
btn(state.editing ? 'Done editing' : 'Edit', () => { state.editing = !state.editing; render(); }, state.editing ? 'primary' : ''))), btn(state.editing ? 'Done editing' : 'Edit', () => { state.editing = !state.editing; render(); }, state.editing ? 'primary' : ''))),
resetRequested && !state.resetOffered ? resetBanner() : null, resetRequested() && !state.resetOffered ? resetBanner() : null,
h('div', { class: 'layout' }, renderNav(), h('div', { class: 'layout' }, renderNav(),
h('main', {}, onHeader ? [h('h2', {}, 'Print header'), headerPanel()] h('main', {}, onHeader ? [h('h2', {}, 'Print header'), headerPanel()]
: sec ? [h('h2', {}, sec.title), state.editing ? editSection(sec) : viewSection(sec)] : sec ? [h('h2', {}, sec.title), state.editing ? editSection(sec) : viewSection(sec)]
: h('p', { class: 'muted' }, 'No sections yet. Choose Edit to add one.')))); : h('p', { class: 'muted' }, 'No sections yet. Choose Edit to add one.'))));
} }
window.addEventListener('hashchange', () => { state.resetOffered = false; render(); });
render(); render();
})(); })();

View File

@@ -2,7 +2,7 @@
// YYMMDD is the date, X the iteration that day (A first, B second, ...). // YYMMDD is the date, X the iteration that day (A first, B second, ...).
// Bump with `npm run bump` (see bump-version.js). build.js strips `export`. // Bump with `npm run bump` (see bump-version.js). build.js strips `export`.
export const APP_VERSION = '261121B'; export const APP_VERSION = '261123A';
const VERSION_RE = /^(\d{6})([A-Z])$/; const VERSION_RE = /^(\d{6})([A-Z])$/;
export const isVersion = (v) => typeof v === 'string' && VERSION_RE.test(v); export const isVersion = (v) => typeof v === 'string' && VERSION_RE.test(v);