Skip to content

Commit

Permalink
Fixes needless custom component recreation (#1195) (#1224)
Browse files Browse the repository at this point in the history
  • Loading branch information
shawncrawley authored Oct 29, 2024
1 parent f70bccd commit 0e4432f
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 4 deletions.
1 change: 1 addition & 0 deletions docs/source/about/changelog.rst
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ Unreleased
- :pull:`1118` - `module_from_template` is broken with a recent release of `requests`
- :pull:`1131` - `module_from_template` did not work when using Flask backend
- :pull:`1200` - Fixed `UnicodeDecodeError` when using `reactpy.web.export`
- :pull:`1224` - Fixes needless unmounting of JavaScript components during each ReactPy render.

**Added**

Expand Down
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 0e4432f

Please sign in to comment.