Investigate a URL-flicker bug in the video-editor route of this Next.js/React app.…
- User
Investigate a URL-flicker bug in the video-editor route of this Next.js/React app.
Repro: on first navigation into the video editor, the browser URL flickers rapidly between: http://localhost:2222/tools/video-editor?timeline=02372e18-f669-46c7-8d64-e74dc66d07c8 http://localhost:2222/tools/video-editor …and the editor UI never loads. A manual page refresh fixes it — the editor loads normally on subsequent loads.
This points to a redirect/replace loop: two effects are fighting, each reacting to the other's URL change and calling router.replace/push in response. Typical culprits:
- An effect that strips the
timelinequery param when it can't find the timeline yet (loading=true / data not hydrated), and another effect that re-adds?timeline=<id>once state loads. - Route guards or layout-level effects running before children have hydrated state.
- Zustand/Redux store hydration resetting a selected-timeline id, causing the URL to be rewritten.
useEffectdependencies that include objects/functions recreated each render, causing the effect to re-fire.
Your task:
- Locate the video-editor route: src/tools/video-editor and its layout/page files (check both the Next.js app router tree under src/app and the tools/video-editor module).
- Find every place that reads or writes the
timelinequery param — especially calls to router.replace, router.push, useSearchParams, useRouter, history.replaceState, or navigate(). - Identify the two (or more) effects/handlers that are ping-ponging. Show the exact file:line pairs and the conditions under which each fires.
- Explain WHY it only happens on first load but not after refresh (hint: server-rendered URL already has the query param so on refresh the state matches; on client-side nav from elsewhere, state starts empty and one side tries to clear while the other tries to restore).
- Recommend the minimal fix (usually: gate the URL-strip effect on a "ready/loaded" flag, or only write the URL in one direction, or use replace with { scroll: false } inside a single source-of-truth effect).
Deliverables: a short written report naming the specific files/lines, the exact loop, and the minimal fix. Do NOT edit any code — investigation only.
- An effect that strips the
- Assistant
I’m tracing the video-editor route and every
timelineURL read/write path first, then I’ll line up the effects that can race on first client-side navigation. - Assistant
I’ve narrowed it to the app-level route state hook plus the editor page. Next I’m reading those files and the route entry points to map the exact
timelinequery flow. - Assistant
I found the main suspect pair inside
VideoEditorPage: one effect deletestimelinewhen the current id is “not in the list,” another re-adds it from persisted settings or the first fetched timeline. I’m now checking route entry helpers and list loading behavior to pin down why first client-side nav trips that condition. - Assistant
There’s another
timelineURL writer insideVideoEditorProvider, but it only runs after the editor has mounted. I’m checking whether it participates in the loop or whether the loop happens earlier while the page is still resolving the firsttimelineId. - Assistant
I’ve confirmed there isn’t a hidden
router.replaceelsewhere doing this. The oscillation is page-local, and the layout hook only amplifies the symptom by hiding the full editor whenevertimelinedisappears from the URL. - Assistant