Skip to content
Source
Sign inSign up
TanStack/router

fix(router): do not reload for a chunk cancelled while the page unloads #8830

OpentheRizwan(GitHub profile, opens in a new tab)wants to merge 1 commit intomain fromrefs/pull/8830/headopened

Showing 9 changed files with 138 additions and 1 deletion (loading 6).

x
0 of 9 viewed, 9 left
8 additions and 0 deletions.changeset/lazy-chunk-unload-no-reload.mdAdded
View file
@@ -0,0 +1,8 @@
+---
+'@tanstack/router-core': patch
+'@tanstack/react-router': patch
+'@tanstack/solid-router': patch
+'@tanstack/vue-router': patch
+---
+​
+Do not reload the page when Firefox or Safari cancel a pending route chunk because the user is leaving the page. The cancellation has the same message as a missing chunk, and the stale-deploy reload replaced the user's navigation. If the page stays after all, the chunk import is retried.
22 additions and 1 deletionpackages/react-router/src/lazyRouteComponent.tsxModified
View file
@@ -1,5 +1,9 @@
import * as React from 'react'
-import { isModuleNotFoundError } from '@tanstack/router-core'
+import {
+ isModuleNotFoundError,
+ waitForPageToStay,
+ watchPageUnload,
+} from '@tanstack/router-core'
import { isServer } from '@tanstack/router-core/isServer'
import { reactUse } from './utils'
import type { AsyncRouteComponent } from './route'
@@ -25,12 +29,17 @@
let loadPromise: Promise<any> | undefined
let comp: T[TKey] | T['default']
let error: any
+ let cancelledByUnload = false
+ let staying: Promise<void> | undefined
​
const load = () => {