fix: guard pushState until router is initialized
This commit is contained in:
parent
4fda863339
commit
83b18645c8
1 changed files with 10 additions and 3 deletions
|
|
@ -106,6 +106,7 @@
|
||||||
|
|
||||||
// Use $state for instant UI updates - initialized from server-provided initialTab
|
// Use $state for instant UI updates - initialized from server-provided initialTab
|
||||||
let activeTab = $state<GridType>(initialTab ?? GridType.Weapon)
|
let activeTab = $state<GridType>(initialTab ?? GridType.Weapon)
|
||||||
|
let routerReady = $state(false) // Guards pushState calls until router is initialized
|
||||||
|
|
||||||
let loading = $state(false)
|
let loading = $state(false)
|
||||||
let error = $state<string | null>(null)
|
let error = $state<string | null>(null)
|
||||||
|
|
@ -272,9 +273,12 @@
|
||||||
activeTab = tab // Instant UI update
|
activeTab = tab // Instant UI update
|
||||||
|
|
||||||
// Update URL without navigation (no load function, instant)
|
// Update URL without navigation (no load function, instant)
|
||||||
const basePath = `/teams/${party.shortcode}`
|
// Only call pushState after router is initialized to avoid errors during SSR/hydration
|
||||||
const newPath = `${basePath}/${tab}s`
|
if (routerReady) {
|
||||||
pushState(newPath, {})
|
const basePath = `/teams/${party.shortcode}`
|
||||||
|
const newPath = `${basePath}/${tab}s`
|
||||||
|
pushState(newPath, {})
|
||||||
|
}
|
||||||
|
|
||||||
// Update selectedSlot to the first valid empty slot for this tab
|
// Update selectedSlot to the first valid empty slot for this tab
|
||||||
const nextEmpty = findNextEmptySlot(party, tab)
|
const nextEmpty = findNextEmptySlot(party, tab)
|
||||||
|
|
@ -594,6 +598,9 @@
|
||||||
// Get edit key for this party if it exists
|
// Get edit key for this party if it exists
|
||||||
editKey = getEditKey(party.shortcode) ?? undefined
|
editKey = getEditKey(party.shortcode) ?? undefined
|
||||||
|
|
||||||
|
// Router is now ready - safe to call pushState
|
||||||
|
routerReady = true
|
||||||
|
|
||||||
// Handle browser back/forward navigation for tabs
|
// Handle browser back/forward navigation for tabs
|
||||||
const handlePopState = () => {
|
const handlePopState = () => {
|
||||||
const path = window.location.pathname
|
const path = window.location.pathname
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue