Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 26 additions & 0 deletions packages/react-meteor-data/suspense/useTracker.tests.js
Original file line number Diff line number Diff line change
Expand Up @@ -428,3 +428,29 @@ Meteor.isClient &&
);
}
);

Meteor.isClient &&
runForVariants(
'suspense/useTracker - component unmount in Strict Mode',
async function (test, useTrackerFn) {
const { simpleFetch } = setupTest();

const Test = () => {
useTrackerFn('TestDocs', simpleFetch);

return null;
};

const { queryByText, findByText, unmount } = render(<Test />, {
container: document.createElement('container'),
wrapper: TestSuspense,
reactStrictMode: true,
});

await new Promise((resolve) => setTimeout(resolve, 100));

unmount();

test.isTrue(true, 'should handle unmount correctly in Strict Mode');
}
);
14 changes: 10 additions & 4 deletions packages/react-meteor-data/suspense/useTracker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -131,8 +131,11 @@ export function useTrackerSuspenseNoDeps<T = any>(key: string, reactiveFn: IReac

// stop the computation on unmount
return () => {
refs.computation?.stop()
delete refs.computation
if (refs.computation) {
refs.computation.stop()
delete refs.computation
}

refs.isMounted = false
}
}, [])
Expand Down Expand Up @@ -192,8 +195,11 @@ export const useTrackerSuspenseWithDeps =
refs.isMounted = true

return () => {
refs.computation.stop()
delete refs.computation
if (refs.computation) {
refs.computation.stop()
delete refs.computation
}

refs.isMounted = false
}
}, deps)
Expand Down