Skip to content

feat(dialog): the browser Forward reopens what Back closed - #39

Open
ivanbanov wants to merge 1 commit into
mainfrom
fix-dialog-forward-navigation
Open

feat(dialog): the browser Forward reopens what Back closed#39
ivanbanov wants to merge 1 commit into
mainfrom
fix-dialog-forward-navigation

Conversation

@ivanbanov

Copy link
Copy Markdown
Member

What

closeOnBack becomes symmetric: the browser's Back closes the dialog (as before), and the browser's Forward now reopens what Back closed — guarded again for the next Back. No new setting: back-close and forward-reopen are one behavior (the dialog's openness tracking the history position), so the existing closeOnBack gates both.

The reopen follows the shared dismissal contract: a new onForwardNavigation callback fires first and preventDefault() vetoes; a controlled dialog only records the intent.

How

The model that keeps this cheap: the guard entry a Back press pops isn't gone — it survives in the browser's forward stack, still marking the dialog's open ground. A traversal re-entering it is the host's Forward.

  • @dunky.dev/dom-navigationinterceptBackNavigation(onBack, onForward?) grew the optional second callback. A Back-closed guard parks instead of dropping; a popstate landing on its spent entry offers the reopen and re-arms the guard on the entry in place (no new entry planted). The safety invariant: parked entries always sit above every armed entry (every planted entry truncates the forward stack), so ownership of the landing entry — not traversal direction, which popstate doesn't carry — decides reopen vs unwind. Marked ground with no armed owner never unwinds a layer; without that, Forward onto a dead nested-dialog entry would wrongly close its parent. Callers that don't pass onForward behave exactly as before.
  • @dunky.dev/dialoghistory.forward mirrors history.back, gated by the same closeOnBack, reachable from closed and from the animated closing state (Forward interrupts the exit). The connect gains forwardNavigate(), sharing the synthesized veto payload with backNavigate().
  • @dunky.dev/react-dialog — one registration spans the whole episode: armed while open, parked through a Back-close (releasing there would end the Forward watch), released on any other close or on unmount. Reopening through the trigger plants a fresh entry, truncating the spent one — exactly like navigating after a Back.

Caveats (spec'd)

  • A controlled dialog's Back-close is completed by the consumer rather than by the press itself, so its entry is consumed and Forward has nothing to re-enter (URL-held open state remains the answer there, per the navigation SPEC's Reload section).
  • The Forward watch lives in script, so it doesn't survive a reload.
  • The Vue binding keeps today's Back-only behavior for now (it passes no onForward); noted next to the react story. Mirroring it is a small follow-up once feat(vue): the Vue substrate, opening with Dialog #38 lands.

Testing

  • 13 new behavior tests: 5 dom-navigation (reopen + re-arm, decline keeps watching, release ends the watch, a planted entry truncates the watch, stacked guards reopen one per Forward lowest-first), 4 core machine/connect, 4 react (Forward reopens guarded again, no reopen after other closes, veto, trigger-reopen truncates).
  • Full suite, typecheck, lint, and format pass; the closeOnBack story gained a "Simulate browser Forward" button.

🤖 Generated with Claude Code

closeOnBack becomes symmetric. The guard entry a Back press pops survives
in the forward stack, still marking the dialog's open ground: a traversal
re-entering it is the host's Forward and reopens the dialog, guarded again
for the next Back. One setting gates both directions.

- dom-navigation: interceptBackNavigation(onBack, onForward?) — a
  Back-closed guard parks instead of dropping; a landing on its spent
  entry offers the reopen and re-arms the guard on the entry in place.
  Ownership of the landing entry, not traversal direction, decides
  reopen vs unwind: marked ground with no armed owner is forward residue
  and never unwinds a layer.
- dialog (core): history.forward mirrors history.back, gated by the same
  closeOnBack, reachable from closed and from the animated closing state
  (Forward interrupts the exit); forwardNavigate() on the api with a new
  onForwardNavigation veto callback, per the shared dismissal contract.
- react-dialog: one registration spans the whole episode — armed while
  open, parked through a Back-close, released on any other close or on
  unmount. Reopening through the trigger plants a fresh entry, truncating
  the spent one, exactly like navigating after a Back.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant