-
Notifications
You must be signed in to change notification settings - Fork 39
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, SWC-7131 - Fixes for ReactComponent widgets #5551
Conversation
@@ -14,8 +14,6 @@ public interface SynapseJSNIUtils { | |||
|
|||
public void highlightCodeBlocks(); | |||
|
|||
void loadSummaryDetailsShim(); |
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.
public void render(ReactElement<?, ?> reactElement) { | ||
this.reactElement = reactElement; | ||
createRootAndRender(); | ||
} |
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.
a bit of refactoring to unify the calls to Timer.run
/Timer.schedule
(setTimeout
) and make it more clear why it's being scheduled. No logical change
if (root != null) { | ||
root.render(React.createElement(React.Fragment)); | ||
} |
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.
onUnload
was inappropriate here. This widget can only contain a React component tree (no widget children), so it's much safer to just render a fragment. This prevents bugs where the root was unmounted and destroyed when it didn't need to be.
@@ -92,11 +92,40 @@ private void createRoot() { | |||
} | |||
} | |||
|
|||
/** | |||
* Asynchronously (in the task queue, via setTimeout) unmounts the root and sets it to null. | |||
*/ | |||
private void destroyRoot() { |
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.
Just as in ReactComponent (v1), move the asynchronous logic inside of destroyRoot
if (shouldDestroyRoot) { | ||
destroyRoot(); | ||
} | ||
|
||
// Create a fresh ReactElement tree and render it | ||
componentToRender.createRoot(); | ||
componentToRender.root.render(componentToRender.createReactElement()); | ||
} | ||
}; | ||
t.schedule(0); | ||
// Schedule rendering | ||
createRootAndRender(); |
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.
Note that even through the timers were changed so destroyRoot
and createRootAndRender
now trigger two timers, they end up on the same queue, so they will execute in order.
…ll extended classes)
@@ -216,20 +234,10 @@ protected void onLoad() { | |||
|
|||
@Override | |||
protected void onUnload() { | |||
super.onUnload(); |
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 super
method is an empty implementation, so this call is not necessary
No description provided.