mirror of
https://github.com/outline/outline.git
synced 2026-11-21 21:44:30 +03:00
* refactor: Adopt React 19 browser-state and filter hooks Rewrite browser-state hooks with useSyncExternalStore, adopt useEffectEvent for latest-ref patterns, and defer client-side filters with useDeferredValue. * fix: Refresh usePersistedState default when key changes * fix: Normalize serialized cache key for undefined values Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com> * iterate --------- Co-authored-by: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
23 lines
794 B
TypeScript
23 lines
794 B
TypeScript
import { useSyncExternalStore } from "react";
|
|
|
|
const subscribe = (onStoreChange: () => void) => {
|
|
// Re-measure when the html element resizes (scrollbar appears/disappears).
|
|
const resizeObserver = new ResizeObserver(onStoreChange);
|
|
resizeObserver.observe(document.documentElement);
|
|
return () => resizeObserver.disconnect();
|
|
};
|
|
|
|
const getSnapshot = (): number =>
|
|
window.innerWidth - document.documentElement.clientWidth;
|
|
|
|
/**
|
|
* Returns the width of the window's vertical scrollbar in pixels, or null
|
|
* if not yet measured. Continuously re-measures as the scrollbar appears or
|
|
* disappears.
|
|
*
|
|
* @returns the scrollbar width, or null before measurement.
|
|
*/
|
|
export default function useWindowScrollbarWidth(): number | null {
|
|
return useSyncExternalStore(subscribe, getSnapshot);
|
|
}
|