(event: PopStateEvent)
| 377 | * That case can happen when the old router injected the history entry. |
| 378 | */ |
| 379 | const onPopState = (event: PopStateEvent) => { |
| 380 | if (!event.state) { |
| 381 | // TODO-APP: this case only happens when pushState/replaceState was called outside of Next.js. It should probably reload the page in this case. |
| 382 | return |
| 383 | } |
| 384 | |
| 385 | // This case happens when the history entry was pushed by the `pages` router. |
| 386 | if (!event.state.__NA) { |
| 387 | window.location.reload() |
| 388 | return |
| 389 | } |
| 390 | |
| 391 | // TODO-APP: Ideally the back button should not use startTransition as it should apply the updates synchronously |
| 392 | // Without startTransition works if the cache is there for this path |
| 393 | startTransition(() => { |
| 394 | dispatchTraverseAction( |
| 395 | window.location.href, |
| 396 | event.state.__PRIVATE_NEXTJS_INTERNALS_TREE |
| 397 | ) |
| 398 | }) |
| 399 | } |
| 400 | |
| 401 | // Register popstate event to call onPopstate. |
| 402 | window.addEventListener('popstate', onPopState) |
nothing calls this directly
no test coverage detected