Skip to content

fix: don't throw when history.state is null after replaceState - #626

Open
tomheaton wants to merge 1 commit into
solidjs:mainfrom
tomheaton:fix/null-history-state-depth
Open

tomheaton wants to merge 1 commit into
solidjs:mainfrom
tomheaton:fix/null-history-state-depth

Conversation

@tomheaton

@tomheaton tomheaton commented Sep 28, 2026 •

Copy link
Copy Markdown

saveCurrentDepth() runs on import and reads window.history.state._depth right after replaceState. In an iOS WKWebView (a Flutter flutter_inappwebview embed in our case) replaceState doesn't throw but history.state stays null, so importing the router throws:

TypeError: null is not an object (evaluating 'window.history.state._depth')

Because it happens at module eval, the whole app bundle fails to load, even when only MemoryRouter is used.

This falls back to history.length - 1, the same value it tries to write. Nothing changes when history.state works.

Added a test that mocks history.state as null and replaceState as a no-op. It fails without the fix.

Same fix for next: #627

@changeset-bot

changeset-bot Bot commented Sep 28, 2026 •

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: 58e2d41

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 1 package
Name Type
@solidjs/router Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@tomheaton
tomheaton force-pushed the fix/null-history-state-depth branch from 05df79a to 58e2d41 Compare October 15, 2026 08:14
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants