fix: blank share url in share dialog [PT-188104620] #358
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.
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
andsharedDocumentUrl
. Utility methods in the form ofgetShareUrl()
,getShareLink()
, andgetEmbed()
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 theEnable Sharing
button. These state variables are set to the return values of thegetShareLink()
andgetEmbed()
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 callinggetShareLink()
andgetShareUrl()
when rendering fixes the bug.