This repository was archived by the owner on Nov 4, 2026. It is now read-only.
Repository navigation
fix(console): a settings page asks before leaving with unsaved edits (objectui#13163) - #13204
Merged
objectstack-fleet[bot] merged 1 commit intoOct 20, 2026
Merged
Conversation
SettingsView kept its draft in component state and nothing stood between it and a departure. While the "N unsaved changes" bar is drawn, a local useUnsavedLeaveGuard hook now arms a beforeunload prompt, a capture-phase same-origin link guard, and a confirmLeave() the "All settings" crumb goes through. The prompt is window.confirm with the existing form.unsavedChanges sentence, as the Setup app's metadata editors already do. Claude-Session: https://claude.ai/code/session_014MXhk1yjWh37d634hLy3p7 Co-authored-by: Claude <noreply@anthropic.com>
Contributor
✅ Console Performance Budget
The eager closure is every chunk the entry reaches through static imports — what the browser fetches and parses before the app renders. The entry chunk on its own is a small fraction of it. 📦 Bundle Size Report
Size Limits
|
Contributor
Author
席位核对 · ACCEPT · objectui#13163 · PR #13204 ·
|
objectstack-fleet
Bot
deleted the
claude/issue-13163-settings-leave-guard
branch
October 20, 2026 09:30
This was referenced Oct 20, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to subscribe to this conversation on GitHub.
Already have an account?
Sign in.
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #13163
Clause-②: no
What was broken
Measured on the card (Setup, Localization): change Default country so the bar reads "1 unsaved change", click Company in the sidebar, and the console navigated at once; the edit was gone.
SettingsView, the one renderer behind everysystem/settings/:namespacepage, keeps its edits in a component-state draft, and nothing stood between that draft and a departure.What changed
apps/console/src/pages/settings/useUnsavedLeaveGuard.ts, local to the console app; no published export moves. While armed it installs abeforeunloadlistener (tab close, reload) and a capture-phaseclicklistener on the document for a same-origin link to another pathname, and it returnsconfirmLeave(go)for the page's own navigations. Both listeners come off when the page goes clean (save, Discard) or unmounts. It followsResourceEditPage's guard (same skips: a modified or non-primary click, atargetother than_self,download, another origin, the same pathname).SettingsViewarms it exactly while the "N unsaved changes" bar is drawn: a loaded page with at least one edit, not the skeleton and not the error card. Its "All settings" crumb now goes throughconfirmLeave.form.unsavedChanges("You have unsaved changes. Are you sure you want to leave?"), which all ten packs already hold. No i18n key is added and no string moves..changeset/13163-settings-leave-guard.md,@object-ui/consolepatch.Why
window.confirm, not the record form's in-app dialogThe card's expected behaviour is a guard, and it names the record form's "Discard changes?" dialog as the one it saw. An in-app dialog is asynchronous, so the link guard would have to cancel every click and then navigate again for the user once they agree. Each way of doing that breaks something here:
navigate(anchor.href)instead has to strip the router basename that a host's injected base-href tag sets (the console resolvesBrowserRouter's basename from it), or it doubles the prefix. It also drops the link's ownonClick(the mobile sidebar's home link closes the sheet in itsonClick), itsreplaceand itsstate. And it turns a plain same-origin anchor's document load into an SPA push.A synchronous
confirmneeds none of that: on OK the click carries on untouched. The Setup app's other page-leave guards already use it (ResourceEditPageandStudioDesignSurface), while the record form's dialog closes an overlay and never has to navigate. The sentence is a leave question, not the form's "If you close this form now", which would be wrong on a page.Measurements (dispatch hypotheses H1 to H4)
c209c93(scratch probe, below): a sidebar link went to the other page at once, a link to another namespace loaded it with the edit gone, the "All settings" crumb went to the hub at once, and a tab close with an edit closed with no prompt. All of these happened without a dialog. Correction: the error card'snavigate(-1)is not a way to lose an edit. That card renders only after a failed load, which draws no fields and no save bar, so there is nothing on screen to lose. It stays unguarded on purpose, and the guard is disarmed there. A namespace-to-namespace move keeps the sameSettingsViewmounted. The draft survives the URL change and is reset only when the new namespace's load succeeds (read fromload, which clears it on success only). So it was lost on that path too, and the guard now covers it as a link to another pathname.window.confirmchosen for the reasons above.Real Chromium, after the fix (scratch probe, not committed)
The real
SettingsViewunder a realBrowserRouterbeside realLinks, served by the console's own Vite on a free port, over a stubbed settings API, driven by Playwright with Chromium 1194:The same driver at the base commit (the BEFORE leg) read
dialogs=[]on every departure:url after=/business-units,/settings/companywith the box back toAcme, and/system/settings. With the tab close, the page closed with no prompt.Tests
New
apps/console/src/pages/settings/__tests__/SettingsView.leaveGuard-13163.test.tsx, 12 tests. It drives the whole page under a realBrowserRouter, the router the console mounts, beside a stand-in sidebar of realLinks, over a stubbedfetch.confirmis a stubbed global because happy-dom's window has none. The prompt is asserted to be the bundle'sen.form.unsavedChanges, which pins the key binding, not the wording.On head
4f32cf4, withpnpm exec vitest run --maxWorkers=2 apps/console/src/pages/settings/from the repo root under the shared verify lock:Test Files 23 passed (23),Tests 192 passed (192),VERDICT command-exit 0.Ablation (fix committed first, then
SettingsView.tsxchecked out atc209c93under a trap that restores fromHEAD): the on-disk hits ofuseUnsavedLeaveGuardwent from 2 to 0, and the barenavigate('/system/settings')crumb came back (1 hit). Result:Tests 6 failed | 6 passed (12). The six that went red are the asks-first family (expected "vi.fn()" to be called 1 times, but got 0 times), the tab-close one (expected false to be true), and the unmount one. The environment control and the five controls stayed green, as expected. The restore was proved by the blob hash equal toHEAD's andgit diff HEADat 0 lines.Gates (local, head
4f32cf4, exit codes captured before any pipe)turbo run build --filter='@object-ui/console^...' --concurrency=2: 34 of 34 successful (28 cached).pnpm --filter @object-ui/console lint: exit 0. It reports 0 errors and 220 warnings, none on the new files. The two warnings onSettingsView.tsxare on lines this PR does not change, moved down one line by the new import.pnpm --filter @object-ui/console type-check:VERDICT command-exit 0. Atsc --noEmit --listFilesrun lists both new files in the program.pnpm check:new-line-citations: exit 0,0 new citation(s).pnpm check:control-bytes: exit 0.node scripts/check-changeset-presence.mjs: exit 0, 1 changeset for 1 released package.pnpm check:i18n-keys: exit 0.pnpm check:i18n-drift: not run. No string moves into the i18n table; an existing key gets its first consumer.node scripts/check-governed-queue-guard.mjs --testover the four paths: NOT GOVERNED.Acceptance notes
Residual: browser Back and Forward (
popstate). It is measured above (RESIDUAL browser Back while dirty: no prompt, edit gone).BrowserRoutergives a page no veto,useBlockerneeds a data router, and history workarounds were not built, per the dispatch. Carrier: none.Residual: shell navigations that start from a button, not an anchor. These bypass the anchor guard: the header's user menu items, the workspace switcher, and a sidebar item's design menu all call
navigate()from a menu item. This is a code reading, not measured in a running shell (no backend was bootable here). It is the same gap theResourceEditPageguard has. Closing it needs a shell-level "page holds unsaved edits" seam in@object-ui/app-shell, which is out of this card's scope. Carrier: none.Observation, dormant: the settings
child_panerow rendershref="#/settings/CHILD", a hash-router-era link. UnderBrowserRouterit only sets the hash and goes nowhere. No manifest in the objectstack tree declares achild_pane, so nothing reaches it. Not filed. Carrier: none.objectui#13146 (a refused save shows the server message verbatim) is queued serially behind this card on the same file. This PR leaves the save and refusal paths and their toasts untouched.
Adds no product-specific widget, dialog, hook or string (see AGENTS.md › Product-neutral renderer)
The session that wrote this PR is
https://claude.ai/code/session_014MXhk1yjWh37d634hLy3p7.Generated by Claude Code