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: blank share url in share dialog [PT-188104620] #358

Merged
merged 2 commits into from
Aug 27, 2024

Conversation

kswenson
Copy link
Member

@kswenson kswenson commented Aug 27, 2024

The ShareDialogView is responsible for displaying the various sharing urls, embedding urls, etc. that result from sharing a document. It constructs these urls from constituent parts passed into it as props, e.g. sharedDocumentId and sharedDocumentUrl. Utility methods in the form of getShareUrl(), getShareLink(), and getEmbed() construct these urls from the provided props. These urls are also stored in state through an asynchronous mechanism that is triggered by the user pressing the Enable Sharing button. These state variables are set to the return values of the getShareLink() and getEmbed() utility methods, which construct them from props, as previously stated. The bug occurs because in v3, the setState callback occurs before the props have been updated, so the state variables are set to empty, and then later the dialog renders the url fields from state, even though the props have been updated by that time. So the explanation for the bug is that there is essentially a race condition and that in v3, perhaps due to the update from React 16 to 18, the ordering of events has changed. The justification for the fix is that since the state is set from the props, the props are always at least as current as the state, and so it is safer/preferable to use the props instead of the state when rendering, and so calling getShareLink() and getShareUrl() when rendering fixes the bug.

@kswenson
Copy link
Member Author

@tealefristoe Doug is the logical person to review this but since he's unavailable, I'm nominating you in his stead. Hopefully, the explanation is sufficient to lend some credence to the fix.

Copy link

@tealefristoe tealefristoe left a comment

Choose a reason for hiding this comment

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

Seems ok to me, though I'll admit that this is a subtle bug I'm pretty unfamiliar with. I guess my only question is do you ever use this.state.link or this.state.embed any more?

@kswenson
Copy link
Member Author

Seems ok to me, though I'll admit that this is a subtle bug I'm pretty unfamiliar with. I guess my only question is do you ever use this.state.link or this.state.embed any more?

Essentially not, and I thought about removing them, but I'm concerned that the setState call that sets them may be triggering a necessary re-render, even if we never actually use the resulting state values, so I'm inclined to not make any further changes than necessary at this point.

@kswenson kswenson merged commit d05967b into master Aug 27, 2024
2 checks passed
@kswenson kswenson deleted the 188104620-fix-blank-share-url branch October 18, 2024 22:25
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.

2 participants