Skip to content

Commit 0f92779

Browse files
docs: Clarify popstate handling to prevent UI freeze on navigation spam (#25)
1 parent a422afa commit 0f92779

File tree

2 files changed

+4
-2
lines changed

2 files changed

+4
-2
lines changed

exercises/04.router/05.problem.cache/ui/index.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,7 @@ function Root() {
6161

6262
// 🐨 change this to setContentKey(historyKey)
6363
startTransition(() => setContentPromise(nextContentPromise))
64+
// 🐨 otherwise, setContentKey(historyKey) directly (no transition needed)
6465
}
6566
window.addEventListener('popstate', handlePopState)
6667
return () => window.removeEventListener('popstate', handlePopState)

exercises/04.router/05.solution.cache/ui/index.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -56,9 +56,10 @@ function Root() {
5656
const fetchPromise = fetchContent(nextLocation)
5757
const nextContentPromise = createFromFetch(fetchPromise)
5858
contentCache.set(historyKey, nextContentPromise)
59+
startTransition(() => setContentKey(historyKey))
60+
} else {
61+
setContentKey(historyKey)
5962
}
60-
61-
startTransition(() => setContentKey(historyKey))
6263
}
6364
window.addEventListener('popstate', handlePopState)
6465
return () => window.removeEventListener('popstate', handlePopState)

0 commit comments

Comments
 (0)