Skip to content

Commit e1150aa

Browse files
committed
Fixes needless custom component recreation (#1195)
1 parent f6f13f0 commit e1150aa

File tree

2 files changed

+5
-4
lines changed

2 files changed

+5
-4
lines changed

src/js/packages/@reactpy/client/src/components.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -177,7 +177,7 @@ function useForceUpdate() {
177177

178178
function useImportSource(model: ReactPyVdom): MutableRefObject<any> {
179179
const vdomImportSource = model.importSource;
180-
180+
const vdomImportSourceJsonString = JSON.stringify(vdomImportSource);
181181
const mountPoint = useRef<HTMLElement>(null);
182182
const client = React.useContext(ClientContext);
183183
const [binding, setBinding] = useState<ImportSourceBinding | null>(null);
@@ -203,7 +203,7 @@ function useImportSource(model: ReactPyVdom): MutableRefObject<any> {
203203
binding.unmount();
204204
}
205205
};
206-
}, [client, vdomImportSource, setBinding, mountPoint.current]);
206+
}, [client, vdomImportSourceJsonString, setBinding, mountPoint.current]);
207207

208208
// this effect must run every time in case the model has changed
209209
useEffect(() => {

src/py/reactpy/reactpy/web/templates/react.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,11 +17,12 @@ export default ({ children, ...props }) => {
1717
};
1818

1919
export function bind(node, config) {
20+
const root = ReactDOM.createRoot(node);
2021
return {
2122
create: (component, props, children) =>
2223
React.createElement(component, wrapEventHandlers(props), ...children),
23-
render: (element) => ReactDOM.render(element, node),
24-
unmount: () => ReactDOM.unmountComponentAtNode(node),
24+
render: (element) => root.render(element),
25+
unmount: () => root.unmount()
2526
};
2627
}
2728

0 commit comments

Comments
 (0)