jotaijs / jotai-scope

MIT License
60 stars 4 forks source link

fix ScopeProvider error for polyfill #54

Closed dmaskasky closed 3 months ago

dmaskasky commented 3 months ago
const cleanupFamiliesSet = new Set<() => void>();
...
currentScope.cleanup = combineVoidFunctions(
  currentScope.cleanup,
  ...cleanupFamiliesSet,
);

The above code polyfills to

currentScope.cleanup = combineVoidFunctions.apply(void 0, [currentScope.cleanup].concat(cleanupFamiliesSet));

This is not correct and leads to arguments being [() => {}, new Set()]. Whereas expected is [() => {}].

The solution is to wrap the set with Array.from.

const cleanupFamiliesSet = new Set<() => void>();
...
currentScope.cleanup = combineVoidFunctions(
  currentScope.cleanup,
  ...Array.from(cleanupFamiliesSet),
);

Tests are not catching this issue either.

codesandbox-ci[bot] commented 3 months ago

This pull request is automatically built and testable in CodeSandbox.

To see build info of the built libraries, click here or the icon next to each commit SHA.