Error on datasource remove

I a using Cesium 1.105.0 with React 18 on StrictMode.
I am adding a datasource to viewer datasources, then removing it on component unmount. When removing it I have this error:

An error occurred while rendering. Rendering has stopped.
TypeError: Cannot read property 'length' of undefined
TypeError: Cannot read property 'length' of undefined
    at DataSourceDisplay.update (http://localhost:6006/node_modules/.vite-storybook/deps/cesium.js?v=1c1f44d1:153412:27)
    at Viewer._onTick (http://localhost:6006/node_modules/.vite-storybook/deps/cesium.js?v=1c1f44d1:250246:45)
    at Event.raiseEvent (http://localhost:6006/node_modules/.vite-storybook/deps/cesium.js?v=1c1f44d1:23095:20)
    at Clock.tick (http://localhost:6006/node_modules/.vite-storybook/deps/cesium.js?v=1c1f44d1:130830:15)
    at CesiumWidget.render (http://localhost:6006/node_modules/.vite-storybook/deps/cesium.js?v=1c1f44d1:214044:37)
    at render2 (http://localhost:6006/node_modules/.vite-storybook/deps/cesium.js?v=1c1f44d1:213460:18)

Here is my code:

 * Context allowing to use a cesium datasource
function DataSourceProvider({ children, collectionName }: { children: ReactNode; collectionName: string; }) {
  const { viewer } = useCesiumViewer();
  const dataSource = useRef<CustomDataSource>(new CustomDataSource(collectionName));

  // Initialize collection
  useEffect(() => {
    if (!viewer.dataSources.contains(dataSource.current)) {

    // Delete collection on component unmount
    return () => {
      if (!viewer.dataSources.isDestroyed() && viewer.dataSources.contains(dataSource.current)) {
        viewer.dataSources.remove(dataSource.current, true);
  }, [viewer]);

  return <DataSourceContext.Provider value={dataSource.current}>{children}</DataSourceContext.Provider>;

I could use datasource.current.entities.removeAll() but the viewer datasources list would keep useless datasources after emptying them.
Even returning null instead of DataSourceContext object, the error still produce on component unmount.

So this error comes from the viewer.datasources.remove function, would you know how to prevent this from happening?

Thank you for your help!