WebReflection / augmentor

Extensible, general purpose, React like hooks for the masses.
https://medium.com/@WebReflection/demystifying-hooks-f55ad885609f
ISC License
134 stars 7 forks source link

Why would values be undefined in createEffect? #30

Closed luke-thorburn closed 3 years ago

luke-thorburn commented 3 years ago

I'm building a moderately sized app using neverland, and am encountering an error that seems to be triggered by the augmentor code.

Specifically, the use of useEffect sometimes triggers the following error:

index.js:192 Uncaught TypeError: Cannot read property '0' of undefined
    at different (index.js:192)
    at Array.some (<anonymous>)
    at index.js:123
    at SelectSubField (DefaultCollection_Doc_SelectSubField.js:60)
    at SubField (DefaultCollection_Doc_SequenceField.js:193)
    at DefaultCollection_Doc_SequenceField.js:251
    at Array.map (<anonymous>)
    at DefaultCollection_Doc_SequenceField.js:247
    at Array.map (<anonymous>)
    at Element (DefaultCollection_Doc_SequenceField.js:244)

Which I have traced back to the createEffect function in augmentor:

const createEffect = asy => (effect, guards) => {
  const i = state.i++;
  const {hook, after, stack, length} = state;
  if (i < length) {
    const info = stack[i];
    const {update, values, stop} = info;
    if (!guards || guards.some(different, values)) {
      // ^^^ Error is triggered on the previous line because 'values' is undefined. ^^^
      // ...

It will be quite a lot of work to create a minimal example so before I do I thought I would ask: can you think of any reason why values would be undefined?

WebReflection commented 3 years ago

can you think of any reason why values would be undefined?

conditional hooks (ternary, hooks within hooks that are guarded hence don't always execute, or any condition where the hook is not always used).

you could try to see if you have the same in µland which is based on µhooks instead, and if the problem is still there, then this is likely the answer.

luke-thorburn commented 3 years ago

Thanks @WebReflection, this helped me resolve the problem well enough for now (by tweaking some of the guarding variables).