import { useCallback, useRef } from 'react'; import { defineChannel } from 'hooks/usePanelChannel'; /** * "The connection changed — anything reading it should read it again." * * A channel and not the URL, because `docs/navigation-audit.md` draws that line at ADDRESSABLE: nobody * links to the moment after a connection was saved, and there is nothing selected. This is the second * kind — a signal. * * The nonce is a module counter rather than `setSignal(n => n + 1)`, copied deliberately from * proxy-manager's own channel, which records why: the functional setter applies against the value * captured at render, so two bumps in one render window both compute `snapshot + 1` and the second is * lost. `Date.now()` has the same flaw twice in a millisecond. A module counter never reads React state. */ const useOpenSeoChangedChannel = defineChannel('openseo:changed', 0); let nonce = 0; export const useOpenSeoChanged = () => { const [signal, setSignal] = useOpenSeoChangedChannel(); const setRef = useRef(setSignal); setRef.current = setSignal; const bump = useCallback(() => setRef.current(++nonce), []); return [signal, bump] as const; };