-
Notifications
You must be signed in to change notification settings - Fork 1.3k
fix(ScrollView): don't report empty visible rect when the content suspends #8215
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -184,7 +184,7 @@ export function useScrollView(props: ScrollViewProps, ref: RefObject<HTMLElement | |
// adjusted space. In very specific cases this might result in the scrollbars disappearing | ||
// again, resulting in extra padding. We stop after a maximum of two layout passes to avoid | ||
// an infinite loop. This matches how browsers behavior with native CSS grid layout. | ||
if (!isTestEnv && clientWidth !== dom.clientWidth || clientHeight !== dom.clientHeight) { | ||
if (!isTestEnv && (dom.checkVisibility?.() ?? true) && (clientWidth !== dom.clientWidth || clientHeight !== dom.clientHeight)) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. checkVisibility is well supported across browsers. Not sure if There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We should be able to use There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think it makes sense to move |
||
state.width = dom.clientWidth; | ||
state.height = dom.clientHeight; | ||
flush(() => { | ||
|
@@ -198,7 +198,7 @@ export function useScrollView(props: ScrollViewProps, ref: RefObject<HTMLElement | |
|
||
// Update visible rect when the content size changes, in case scrollbars need to appear or disappear. | ||
let lastContentSize = useRef<Size | null>(null); | ||
let [update, setUpdate] = useState({}); | ||
let [update, setUpdate] = useState<{} | false>(false); | ||
useLayoutEffect(() => { | ||
if (!isUpdatingSize.current && (lastContentSize.current == null || !contentSize.equals(lastContentSize.current))) { | ||
// React doesn't allow flushSync inside effects, so queue a microtask. | ||
|
@@ -224,7 +224,9 @@ export function useScrollView(props: ScrollViewProps, ref: RefObject<HTMLElement | |
|
||
// Will only run in tests, needs to be in separate effect so it is properly run in the next render in strict mode. | ||
useLayoutEffect(() => { | ||
updateSize(fn => fn()); | ||
if (update) { | ||
updateSize(fn => fn()); | ||
} | ||
}, [update]); | ||
|
||
let onResize = useCallback(() => { | ||
|
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Unrelated to this change,
clientWidth !== dom.clientWidth || clientHeight !== dom.clientHeight
missed parenthesis for the if condition to make more sense.