Skip to content

Commit c5a95ac

Browse files
authored
fix(web): seed contest source track from URL when permalink resolves (#14370)
1 parent 8f27fa6 commit c5a95ac

1 file changed

Lines changed: 20 additions & 0 deletions

File tree

packages/web/src/pages/host-remix-contest-page/HostRemixContestPage.tsx

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -281,6 +281,26 @@ export const HostRemixContestPage = () => {
281281
hasHydratedRef.current = true
282282
}, [remixContest, draft])
283283

284+
// On the track-scoped route (/:handle/:slug/host-contest) the URL
285+
// identifies the source track, but `useTrackByPermalink` is async — by
286+
// the time it resolves, the `useState` initializer above has already
287+
// captured `primaryTrackId === undefined` and seeded `sourceTrackIds`
288+
// to `[]`. Without this sync, the Source Track section shows "+ Add
289+
// Track" instead of the URL's track and the Launch button stays
290+
// disabled forever (`sourceTrackIds.length === 0`), so clicking Launch
291+
// appears to do nothing. Run once when `primaryTrackId` first
292+
// resolves; skip if state was already populated from a draft or
293+
// existing contest, and never re-populate after a user removes the
294+
// row.
295+
const hasSeededPrimaryTrackRef = useRef(false)
296+
useEffect(() => {
297+
if (hasSeededPrimaryTrackRef.current) return
298+
if (!primaryTrackId) return
299+
hasSeededPrimaryTrackRef.current = true
300+
if (sourceTrackIds.length > 0) return
301+
setSourceTrackIds([primaryTrackId])
302+
}, [primaryTrackId, sourceTrackIds.length])
303+
284304
// The event's backing track: prefer the URL-scoped primary track, and
285305
// fall back to the (required) first Source Track when entering from the
286306
// track-less /host-contest route. This is the `entity_id` on create /

0 commit comments

Comments
 (0)