Skip to content

Commit

Permalink
Fixes needless custom component recreation (#1195)
Browse files Browse the repository at this point in the history
  • Loading branch information
shawncrawley committed Jul 18, 2024
1 parent f6f13f0 commit e1150aa
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 4 deletions.
4 changes: 2 additions & 2 deletions src/js/packages/@reactpy/client/src/components.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,7 @@ function useForceUpdate() {

function useImportSource(model: ReactPyVdom): MutableRefObject<any> {
const vdomImportSource = model.importSource;

const vdomImportSourceJsonString = JSON.stringify(vdomImportSource);
const mountPoint = useRef<HTMLElement>(null);
const client = React.useContext(ClientContext);
const [binding, setBinding] = useState<ImportSourceBinding | null>(null);
Expand All @@ -203,7 +203,7 @@ function useImportSource(model: ReactPyVdom): MutableRefObject<any> {
binding.unmount();
}
};
}, [client, vdomImportSource, setBinding, mountPoint.current]);
}, [client, vdomImportSourceJsonString, setBinding, mountPoint.current]);

// this effect must run every time in case the model has changed
useEffect(() => {
Expand Down
5 changes: 3 additions & 2 deletions src/py/reactpy/reactpy/web/templates/react.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,12 @@ export default ({ children, ...props }) => {
};

export function bind(node, config) {
const root = ReactDOM.createRoot(node);
return {
create: (component, props, children) =>
React.createElement(component, wrapEventHandlers(props), ...children),
render: (element) => ReactDOM.render(element, node),
unmount: () => ReactDOM.unmountComponentAtNode(node),
render: (element) => root.render(element),
unmount: () => root.unmount()
};
}

Expand Down

0 comments on commit e1150aa

Please sign in to comment.