Skip to content

Commit

Permalink
SWC-7038 - React component render should also be scheduled
Browse files Browse the repository at this point in the history
  • Loading branch information
nickgros committed Aug 30, 2024
1 parent 4e83b19 commit 122660b
Showing 1 changed file with 10 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -143,15 +143,22 @@ private void injectChildWidgetsIntoComponent() {

public void render(ReactNode<?> reactNode) {
this.reactElement = reactNode;
maybeCreateRoot();
injectChildWidgetsIntoComponent();

// This component may be a React child of another component. If so, we must rerender the ancestor component(s) so
// that they use the new ReactElement created in this render step.
ReactComponent<?> componentToRender = getRootReactComponentWidget();
if (componentToRender == this) {
// Resynchronize with the DOM
root.render(this.reactElement);
// Asynchronously schedule creating a root in case React is still rendering and may unmount the current root
Timer t = new Timer() {
@Override
public void run() {
maybeCreateRoot();
// Resynchronize with the DOM
root.render(reactElement);
}
};
t.schedule(0);
} else {
// Walk up the tree to the parent and repeat rerendering
componentToRender.rerender();
Expand Down

0 comments on commit 122660b

Please sign in to comment.