-
-
Notifications
You must be signed in to change notification settings - Fork 1.3k
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
Fix reloading when using useAnimatedKeyboard #3932
Merged
Merged
Changes from 1 commit
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
Using this function may lead to deadlocks in some cases, can't we just run this block asynchronously?
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.
You don't want listeners to be run after
clearListeners
has been called, that's the root of the issue here.If you call it asynchronously, after scheduling this block the js runtime will be cleaned up, and if the listeners run before this block is executed, you get a crash.
That said, there may be better way of doing this, like having an atomic boolean
invalidated
which stops the listeners from being called - might be worth trying out.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.
I was thinking of other ways to do this.
The problem with boolean is that at some point before calling the listeners I we have to check if the boolean is set. Something like this:
and now what if we invalidate js runtime while calling the listeners? It is still going to crash.
We can try checking the boolean before calling every listener like this:
I didn't test it but I think there is still a couple of instructions between checking the boolean and actually calling a listener so theoretically it can still crash.
I think there is no way around the fact that js thread has to wait somehow for the main thread to finish calling listeners.
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.
The check would have to somehow be done on the JS thread, this way you won't be able to invalidate the runtime while running the listener, since operations on the same thread won't be interleaved. That said, if these listeners run on the main thread, why do they use the JS thread runtime?
Or am I misunderstanding and the UI thread runtime is destroyed on the JS thread for some reason?
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.
According to the xcode debugger it is destroyed on the JS thread. You can even see it on the second screenshot.
Or is it the js runtime destroyed... 🤔
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.
So the UI thread runtime is destroyed on the JS thread and called on the main thread and we rather can't change that. So I have no other idea than synchronising threads like that.
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.
I'd say, the current approach is ok.
I don't think we expect the reload to come from the main thread, so there shouldn't be any deadlocks here.
Actually, does this listener actually run on the JS thread? I'm not sure where
NSNotificationCenter
listeners run.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.
So I guess they are run from JS thread then 👍.