Skip to content

Commit ce38c31

Browse files
committed
fix: prevent URL overwrite during async decompression
Add isInitialLoadRef to skip updateURL during initial page load, preventing compressed URLs from being overwritten before decompression completes. Mark initial load complete when state is successfully decoded or when starting with empty URL. Fixes issue where animations wouldn't load on first visit and required a page refresh.
1 parent 4c5ee4b commit ce38c31

File tree

1 file changed

+12
-2
lines changed

1 file changed

+12
-2
lines changed

src/App.tsx

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ import {
99
Timestamp,
1010
where,
1111
} from 'firebase/firestore'
12-
import { useEffect, useState } from 'preact/hooks'
12+
import { useEffect, useRef, useState } from 'preact/hooks'
1313
import {
1414
approveSubmission,
1515
getUserEmails,
@@ -56,6 +56,7 @@ export const App = () => {
5656
useState<Submission | null>(null)
5757
const [showInfoModal, setShowInfoModal] = useState(false)
5858
const [clipboard, setClipboard] = useState<Frame | null>(null)
59+
const isInitialLoadRef = useRef(true)
5960

6061
const userIsAdmin = isAdmin
6162
const pendingCount = mySubmissions.filter(
@@ -166,8 +167,11 @@ export const App = () => {
166167
return unsubscribe
167168
}, [])
168169

169-
// Update URL when state changes
170+
// Update URL when state changes (skip initial load to prevent overwriting compressed URLs)
170171
useEffect(() => {
172+
if (isInitialLoadRef.current) {
173+
return
174+
}
171175
updateURL(state)
172176
}, [state])
173177

@@ -185,6 +189,8 @@ export const App = () => {
185189
selectedColorIndex: prevState.selectedColorIndex,
186190
currentFrameIndex: prevState.currentFrameIndex,
187191
}))
192+
// Mark initial load as complete after successfully loading state from URL
193+
isInitialLoadRef.current = false
188194
}
189195
}
190196

@@ -208,6 +214,10 @@ export const App = () => {
208214
const pendingState = getPendingDecodedState()
209215
if (pendingState) {
210216
setState(pendingState)
217+
isInitialLoadRef.current = false
218+
} else if (!window.location.hash) {
219+
// No URL hash means we're starting fresh - mark initial load complete
220+
isInitialLoadRef.current = false
211221
}
212222

213223
return () => {

0 commit comments

Comments
 (0)