fix(nav): the address keeps what the app rewrites around it (review round 3)
- The Feed press over a live search ends only the search: the feed's own view stays named. - Leaving a search steps back only off an entry the app pushed (_ytOwn); one a link or a reload opened is cleared in place, also where the Navigation API is missing. - useUrlMirror rewrites a changed view through replaceView, so a reload's overlay marks go; its first write and its landing writes keep them for an overlay that reopens. - Files and Playlists: a box emptied and filled again settles at once, never naming the ended search. - Playlists: a linked player is scoped to the playlist the store started with, and only the rail's own move to the first playlist is no pick. - Contract: writer objects are scanned to their matching brace, a computed or shorthand key is refused, and every useHistorySubview call hands a named definition. - Lint: playwright/no-skipped-test also refuses fixme (gate snapshot regenerated). - FEED_DEFAULT_SORT at the three remaining sites; linkedNotListed says to search by name.
This commit is contained in:
@@ -1,4 +1,5 @@
|
||||
import { useEffect, useEffectEvent, useState } from "react";
|
||||
import { useEffect, useEffectEvent, useRef, useState } from "react";
|
||||
import { replaceView } from "./history";
|
||||
import { urlWithParams } from "./urlState";
|
||||
|
||||
// Mirror a set of nav params onto the CURRENT history entry (replaceState — mirroring is not a new
|
||||
@@ -19,11 +20,20 @@ export function useUrlMirror(updates: Record<string, string | null>): void {
|
||||
// The object itself is read through an effect event, so the effect's reactive inputs are the
|
||||
// serialized value and the landing count — which is exactly what the dep list says: an effect event
|
||||
// for the identity that churns, primitives for the triggers.
|
||||
// A change of what this mirror writes, after its first write, is another view on the same entry
|
||||
// (replaceView: it drops the marks a reload under an overlay left). Its first write on a mount and
|
||||
// its write on a landing name the view the entry already shows, so the marks stay: an overlay that
|
||||
// reopens after a reload still finds its entry.
|
||||
const written = useRef<string | null>(null);
|
||||
const mirror = useEffectEvent(() => {
|
||||
const href = urlWithParams(updates);
|
||||
const changed = written.current != null && written.current !== dep;
|
||||
written.current = dep;
|
||||
// Every mirror runs on every landing: one with nothing to change writes nothing (a browser
|
||||
// throttles a page that rewrites its address too often).
|
||||
if (href !== urlWithParams({})) window.history.replaceState(window.history.state, "", href);
|
||||
if (href === urlWithParams({})) return;
|
||||
if (changed) replaceView(window.history.state ?? {}, href);
|
||||
else window.history.replaceState(window.history.state, "", href);
|
||||
});
|
||||
// Counted in state, on a task after the popstate dispatch: every listener of it has run by then —
|
||||
// a store that reads its keys back from the landed address among them (Activity) — and so has the
|
||||
|
||||
Reference in New Issue
Block a user