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

SWC-7102 #5551

Open
wants to merge 2 commits into
base: develop
Choose a base branch
from
Open

SWC-7102 #5551

wants to merge 2 commits into from

Conversation

nickgros
Copy link
Contributor

No description provided.

@@ -14,8 +14,6 @@ public interface SynapseJSNIUtils {

public void highlightCodeBlocks();

void loadSummaryDetailsShim();
Copy link
Contributor Author

@nickgros nickgros Oct 17, 2024

Choose a reason for hiding this comment

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

details-shim was removed in #5346

I missed these references to the module, so removing them here will make an error message in the console go away. This does not fix SWC-7102

@@ -61,14 +61,18 @@ protected void onLoad() {

@Override
protected void onUnload() {
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 the scenario triggering the bug in SWC-7102 is that a ReactComponent widget is unloaded and then re-loaded almost immediately. Since this.root from the first load, which cannot be reused after unmount is called, is still present when the second load happens, React throws an error.

We unmount the root asynchronously because because the call to onUnload may have been triggered within React's render cycle, which is also not allowed. Putting the unmount call in a Timer schedules it in the task queue, which will run after React finishes rendering (which happens in the microtask queue).

To fix this, we can synchronously clear the widget's this.root field, while still deferring the call to unmount.

@@ -94,8 +94,17 @@ private void createRoot() {

private void destroyRoot() {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Add the same logic to ReactComponentV2.

oldRoot.unmount();
}
};
t.schedule(0);
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Move the timer logic to the helper method

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.

1 participant