mirror of
https://github.com/outline/outline.git
synced 2026-12-04 10:24:43 +03:00
fix: Guard scrollbar width hook against a missing documentElement (#14788)
This commit is contained in:
1 parent
3d5e9c1da1
commit
0d8201962d
1 file changed
+9
-2
@@ -1,14 +1,21 @@
|
||||
import { useSyncExternalStore } from "react";
|
||||
|
||||
const subscribe = (onStoreChange: () => void) => {
|
||||
if (!document.documentElement) {
|
||||
return () => {};
|
||||
}
|
||||
|
||||
// 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;
|
||||
// documentElement can be null while some in-app browsers replace the document.
|
||||
const getSnapshot = (): number | null =>
|
||||
document.documentElement
|
||||
? window.innerWidth - document.documentElement.clientWidth
|
||||
: null;
|
||||
|
||||
/**
|
||||
* Returns the width of the window's vertical scrollbar in pixels, or null
|
||||
|
||||
Reference in new issue
Block a user