-
-
Notifications
You must be signed in to change notification settings - Fork 87
Ensure that "scrollToIndex" function continues to work when errors occur #750
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?
Conversation
@m-a-r-c-e-l-i-n-o const ok = await initialized;
if (!ok) {
return
} The uncaught reject means the Virtualizer component was unmounted. So I think we shouldn't continue the current scrollToIndex and should reschedule again on next remount. The freezing was probably caused by microtask() call, because microtask is usually scheduled earlier than animation frame. |
I agree with you that in theory ![]() Maybe there is some state that is bleeding because somehow the Lastly, your suggestion would get rid of the "uncaught" error, but the |
Thank you. And I'd like to know well how you are using this component. If the lifecycle of Virtualizer and the scrollable element is the same, it's ok to cancel scrollTo and reschedule on remount, as I suggested. const List = () => {
const ref = useRef(null);
const scrollRef = useRef(null);
useEffect(() => { ref.curernt.scrollToIndex(...) }, [])
return (
<div style={{ overflowY: "auto" }} ref={scrollRef}>
<Virtualizer ref={ref} scrollRef={scrollRef}>
{...}
</Virtualizer>
</div>
);
} But if it's not the same, if virtualizer unmounts but the parent does not, maybe we should not cancel scrollTo. For example, in the case below, React may not unmount viewportElement even if mounted is false: const List = () => {
const ref = useRef(null);
const scrollRef = useRef(null);
return mounted ? (
<div style={{ overflowY: "auto" }} ref={scrollRef}>
<Virtualizer ref={ref} scrollRef={scrollRef}>
{...}
</Virtualizer>
</div>
) : (
<div style={{ overflowY: "auto" }} ref={scrollRef}>
<SomeComponent />
</div>
);
}; |
@inokawa I am not using ![]() ![]() |
I removed all promise rejections(including #750 (comment)) from virtua in I'm not sure if the problem still exists or not. Also not sure what |
Hey @inokawa, the errors are gone, but the issue with You should be able to see that the chat doesn't scroll down on page reload about 90% of the time and about 50% of the time it will still be broken after 3 seconds. Usually when it's broken after 3 seconds, it's permanently broken — the |
Hey @inokawa, so this PR is more symbolic than anything else because I think you can come up with a better way to go about this. It has to do with a side effect of the changes that were made related to #733
The good news is that with the changes you've made so far (version:
0.43.4
), I have not been able to reproduce any of the browser freezing that I spoke about before, however under the same conditions, I now get an undefined "uncaught" error that prevents thescrollToIndex()
from working when initially loading the list. I have tracked that down to the activity inscheduleImperativeScroll
. More specifically theawait initialized;
that errors out and prevents theviewportElement!.scrollTo
from running. Seems that when the error occurs, theviewportElement
element is still there and callingviewportElement!.scrollTo()
is what makes the list work as expected when initially loading, despite the error.The changes I am suggesting in this PR allows the code to continue down to execute
viewportElement!.scrollTo
, but tries to prevent thewhile (true)
from getting out of control, which I theorize that it (the while loops) must be what was causing the browser freezing before. I plan on going to back to previous versions of Virtua to double check, but it would make sense that it would be caused by something running non-stop forever, hugging up all of the resources and freezing everything. Which begs the question, why use while loops with promises? Maybe something more insightful like a recursive function might a better measure, considering that a stack overflow error might make it easier to pin point the general nature of the freeze.At any rate, the changes proposed here passes all of the tests (and works as expected on my app), but it brings about multiple errors:

The "uncaught" error is understandable because it's being thrown by the

cancelScroll
, which we can just suppress. But I have no idea what theSES_UNCAUGHT_EXCEPTION
error is truly about.The

SES_UNCAUGHT_EXCEPTION
error:I suppose that another possibility for the freezing would have been

microtask
because of:But that is far more relevant to #733 than to this PR.