thomashoneyman/purescript-halogen-hooks

Finalizers for useTickEffect and useLifecycleEffect run twice upon component removal

JordanMartinez opened this issue · 3 comments

When I compile #8's "shared" approach (i.e. all hooks are run in one component), then when I remove the component entirely, the useLifecycleEffect and useTickEffect finalizers get run twice. Here's the output of the entire thing:

-- initialization
useMemo: recalculating expensive value1
useMemo: recalculating expensive value2
useMemo: recalculating expensive value3
useLifecycleEffect: this message appears when component is initialized.
useTickEffect: This message appears in two situations. First, when the component is initialized. Second, every time the state value changes, but it appears only AFTER the cleanup message appears.

-- click button that removes entire component
useLifecycleEffect: this message appears when component is removed.
useTickEffect: [Cleanup Message]. This message appears in two situations. First, every time the state value changes. Second, when component is removed.
useLifecycleEffect: this message appears when component is removed.
useTickEffect: [Cleanup Message]. This message appears in two situations. First, every time the state value changes. Second, when component is removed.

Note: this issue still arises even when I update the code to use the fix in #12.

Ah... I see. It's because the Finalize case in the UseEffect will run all finalizers for all hooks rather than just the finalizer for that hook.

Yup. That fixes it. I'm pushing the fix to #12 as well.