Files
outline/app/hooks/useWindowScrollPosition.ts
Tom MoorandClaude Opus 5.5 5647621224 chore: Prune redundant comments and type suppressions (#14124)
* chore: Prune redundant comments and normalize lint directives

Removes comments that restate the following line and stale TODOs, drops
the passive event listener feature check now that all supported browsers
support it, and renames eslint directives to oxlint.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01BehTjuZwKbN5csMCp3H4QH

* fix: Evaluate restricted team domains at validation time

The restricted email provider list was captured when the model loaded, so
it could not follow the hosting environment and the tests that covered it
never reached the model.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01BehTjuZwKbN5csMCp3H4QH

* chore: Replace type suppressions with accurate types

Adds a Concrete helper type for registries of abstract classes, declares
missing Sequelize and refractor typings, uses public ProseMirror APIs, a
typed mock context helper in middleware tests, and a StaticLink component
for sidebar rows being edited.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01BehTjuZwKbN5csMCp3H4QH

---------

Co-authored-by: Claude <noreply@anthropic.com>
2026-10-17 17:07:39 -04:00

54 lines
1.6 KiB
TypeScript

// Based on https://github.com/rehooks/window-scroll-position which is no longer
// maintained.
import { throttle } from "es-toolkit/compat";
import { useCallback, useRef, useSyncExternalStore } from "react";
type ScrollPosition = { x: number; y: number };
const defaultOptions = {
throttle: 100,
};
/**
* Hook to track the window's scroll position.
*
* @param options Configuration options
* @param options.throttle Time in milliseconds to throttle the scroll event
* @returns Object containing the current scroll position (x, y coordinates)
*/
export default function useWindowScrollPosition(options: {
throttle: number;
}): ScrollPosition {
const throttleMs = options.throttle ?? defaultOptions.throttle;
// Cache the last object so getSnapshot returns a stable reference while the
// position is unchanged, which useSyncExternalStore requires.
const cache = useRef<ScrollPosition>({
x: window.pageXOffset,
y: window.pageYOffset,
});
const getSnapshot = useCallback(() => {
const x = window.pageXOffset;
const y = window.pageYOffset;
if (x !== cache.current.x || y !== cache.current.y) {
cache.current = { x, y };
}
return cache.current;
}, []);
const subscribe = useCallback(
(onStoreChange: () => void) => {
const handleScroll = throttle(onStoreChange, throttleMs);
window.addEventListener("scroll", handleScroll, { passive: true });
return () => {
handleScroll.cancel();
window.removeEventListener("scroll", handleScroll);
};
},
[throttleMs]
);
return useSyncExternalStore(subscribe, getSnapshot);
}