Skip to content

Commit 5b5cbf4

Browse files
authored
fix(tv): don't stamp ?ch= on load, only after the viewer tunes (#279)
The TV channel writeback effect ran for the initial auto-selected channel, so a fresh visit to the homepage immediately rewrote the URL to `?ch=<propNumber>`. Gate the writeback behind a ref that flips only when the viewer actually tunes a channel. A clean load now keeps a clean URL; a `?ch=` deep link still selects on load and is preserved.
1 parent bab1e27 commit 5b5cbf4

1 file changed

Lines changed: 7 additions & 1 deletion

File tree

src/components/tv/GnarsTVSet.tsx

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -187,6 +187,11 @@ export function GnarsTVSet({ channels, ticker }: GnarsTVSetProps) {
187187

188188
const active = channels[index] ?? channels[0];
189189

190+
// `?ch=` is only written to the URL after the viewer actually tunes a channel
191+
// — never for the initial auto-selected channel. Keeps a fresh load's URL
192+
// clean; a `?ch=` deep link stays as-is until the viewer changes it.
193+
const userHasTunedRef = useRef(false);
194+
190195
useEffect(() => {
191196
const mq = window.matchMedia("(prefers-reduced-motion: reduce)");
192197
const apply = () => setReducedMotion(mq.matches);
@@ -205,7 +210,7 @@ export function GnarsTVSet({ channels, ticker }: GnarsTVSetProps) {
205210
}, [channels]);
206211

207212
useEffect(() => {
208-
if (!active) return;
213+
if (!active || !userHasTunedRef.current) return;
209214
const url = new URL(window.location.href);
210215
url.searchParams.set("ch", String(active.propNumber));
211216
window.history.replaceState(null, "", url);
@@ -256,6 +261,7 @@ export function GnarsTVSet({ channels, ticker }: GnarsTVSetProps) {
256261
setTuning(true);
257262
clearTimeout(tuneTimer.current);
258263
tuneTimer.current = setTimeout(() => {
264+
userHasTunedRef.current = true;
259265
setIndex(target);
260266
setTuning(false);
261267
}, TUNE_MS);

0 commit comments

Comments
 (0)