Skip to content

Commit 5733044

Browse files
committed
Attempt fix for flaky ReactJS component mounting
1 parent b7f533b commit 5733044

File tree

1 file changed

+5
-3
lines changed

1 file changed

+5
-3
lines changed

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

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -178,23 +178,25 @@ function useImportSource(model: ReactPyVdom): MutableRefObject<any> {
178178

179179
useEffect(() => {
180180
let unmounted = false;
181+
let currentBinding: ImportSourceBinding | null = null;
181182

182183
if (vdomImportSource) {
183184
loadImportSource(vdomImportSource, client).then((bind) => {
184185
if (!unmounted && mountPoint.current) {
185-
setBinding(bind(mountPoint.current));
186+
currentBinding = bind(mountPoint.current);
187+
setBinding(currentBinding);
186188
}
187189
});
188190
}
189191

190192
return () => {
191193
unmounted = true;
192194
if (
193-
binding &&
195+
currentBinding &&
194196
vdomImportSource &&
195197
!vdomImportSource.unmountBeforeUpdate
196198
) {
197-
binding.unmount();
199+
currentBinding.unmount();
198200
}
199201
};
200202
}, [client, vdomImportSourceJsonString, setBinding, mountPoint.current]);

0 commit comments

Comments
 (0)