Skip to content
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: check if its first render before updating from props #419

Merged

Conversation

hannojg
Copy link
Contributor

@hannojg hannojg commented Jul 5, 2024

Details

See: Expensify/App#43983 (comment)

It's possible that the props aren't updated yet on the JS side, while the native state already is. In that case we'd drop the native state for a stale prop value which is incorrect. So we should make sure to only run this code on the first render.

Related Issues

Expensify/App#43983
Expensify/App#44185

Manual Tests

I think its hard to add a specific test for this change.
I verified that the condition is executed on the first render.

Linked PRs

I don't understand this point 😅

@hannojg
Copy link
Contributor Author

hannojg commented Jul 5, 2024

cc @j-piasecki

@tomekzaw tomekzaw requested a review from j-piasecki July 5, 2024 09:34
ios/MarkdownCommitHook.mm Outdated Show resolved Hide resolved
@hannojg hannojg force-pushed the fix/race-condition-props-state-updates branch from 1d33c03 to 0fc17f6 Compare July 5, 2024 09:43
auto plainString =
std::string([[nsAttributedString string] UTF8String]);
if (plainString != textInputProps.text) {
if (textInputState.getRevision() == State::initialRevisionValue && plainString != textInputProps.text) {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we can even skip comparing state text with props text, but it's been a while since I've touched this code so I'm not sure. We can merge this as-is to fix the issue and investigate it further later.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we can even skip comparing state text with props text,

Yeah I was wondering the same. I think the only case where state == props on first render is when the input is empty 🤔 (but not 100% sure either)

@tomekzaw
Copy link
Collaborator

tomekzaw commented Jul 5, 2024

Unfortunately I get a crash here :(

Just run the example app with new arch enabled on iOS and press "Reset" or "Clear" button

There's another crash on main but I'm working on it

edit: okay i think it's my fault

Screenshot 2024-07-05 at 11 53 20

@hannojg
Copy link
Contributor Author

hannojg commented Jul 5, 2024

let me test on the new arch 🤔 thanks for checking!

// Edit: oh okay, so you say the bug isn't caused by this PR? @tomekzaw

@tomekzaw
Copy link
Collaborator

tomekzaw commented Jul 5, 2024

@hannojg Yep, my fault, see PR #420 (we'll merge that in a few minutes)

@hannojg
Copy link
Contributor Author

hannojg commented Jul 5, 2024

Cool, do you think when we merge this one soon and could do a new version? asking because I am wondering whether I should create a pr with a patch in newdiot, or If I should just wait a few minutes and then we can do a PR with a version bump?

@tomekzaw
Copy link
Collaborator

tomekzaw commented Jul 5, 2024

@hannojg Yeah I think we can merge your PR soon, just wanted to test it out. No need for patch right now.

Right now I'm waiting for the CIs on my PR.

@tomekzaw
Copy link
Collaborator

tomekzaw commented Jul 5, 2024

@hannojg Could you please merge main?

…n into fix/race-condition-props-state-updates
@hannojg
Copy link
Contributor Author

hannojg commented Jul 5, 2024

Done!

Copy link
Collaborator

@tomekzaw tomekzaw left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the PR!

@tomekzaw tomekzaw merged commit fbaf59f into Expensify:main Jul 5, 2024
5 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants