Skip to content

Fix historyPoppedToLocationWithRestoration Not a Function - #97

Merged
dajinchu merged 1 commit into
masterfrom
dc/fix-history-nav-stub-rerun
Sep 18, 2026
Merged

dajinchu merged 1 commit into
masterfrom
dc/fix-history-nav-stub-rerun

Conversation

@dajinchu

@dajinchu dajinchu commented Sep 18, 2026 •

Copy link
Copy Markdown
Collaborator

Fixes Turbolinks.controller.historyPoppedToLocationWithRestorationIdentifier is not a function on history navigation.

How it happens

  1. Land on a native bifrost page. Its head has the inline window.Turbolinks stub from headHtmlBegin.
  2. Navigate to wrapped page A, then wrapped page B. Leaving A snapshots document.head, which still contains the stub.
  3. Back to A restores the snapshot. mergeHead executes every head script not recorded as already run, so the stub runs again and replaces the real window.Turbolinks.
  4. Forward to B: onBeforeRoute calls the method on the stub's controller, which doesn't have it.

Root cause
Only wrapped hydration called recordExistingHeadScripts(). Entering on a native page never recorded the scripts the browser had already run, so the stub looked new on restore.

Fix

  • Record existing head scripts on native hydration too, without setting the tracked-script baseline (a native page's first merge into a tracked wrapped page must still not reload).
  • Guard the inline stub so it never replaces a started Turbolinks.
  • e2e: native → wrapped → wrapped → back → forward → back.

🤖 Generated with Claude Code

Snapshots clone the live head, which still holds the inline Turbolinks
stub from the page the session started on. Only wrapped hydration marked
existing head scripts as already run, so after a native entry the first
restore visit re-executed the stub and reset window.Turbolinks. The next
history navigation then failed with
`historyPoppedToLocationWithRestorationIdentifier is not a function`.

- Record existing head scripts on native hydration too.
- Keep the tracked-script baseline separate from script recording, so a
  native page's first merge into a tracked wrapped page still never
  reloads.
- Guard the inline stub so it never replaces a started Turbolinks.
- Add e2e: native -> wrapped -> wrapped -> back -> forward -> back.

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
@dajinchu
dajinchu force-pushed the dc/fix-history-nav-stub-rerun branch from f72bdd2 to 83cb4c2 Compare September 18, 2026 16:54
@dajinchu
dajinchu merged commit b4eddd8 into master Sep 18, 2026
2 checks passed
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