hyperapp icon indicating copy to clipboard operation
hyperapp copied to clipboard

Cannot read properties of null (reading 'length')

Open sergey-shpak opened this issue 2 years ago • 5 comments

Hey, when stopping the app by dispatching null, the following error is thrown: "Cannot read properties of null (reading 'length')".

It looks like the issue is caused by the following code:

if ((state = newState) == null) dispatch = subscriptions = render = id
if (subscriptions) subs = patchSubs(subs, subscriptions(state), dispatch)

When null is dispatched, the subscriptions variable becomes a reference to (a) => a. As a result, it returns null when called with patchSubs(subs, subscriptions(state), dispatch) instead of an array (which is causing the issue)

sergey-shpak avatar Mar 05 '23 19:03 sergey-shpak

btw, similar issue happens with view function - when app is stopped by dispatching null but then deferred render is triggered by requestAnimationFrame. At the moment render is running view is referring to (a) => a and returns null - which is causing following error at 'dom patch': "Cannot read properties of null (reading 'tag')"

sergey-shpak avatar Mar 06 '23 10:03 sergey-shpak

The docs say, about stopping apps:

Calling the dispatch function with no arguments frees the app's resources and runs every active subscription's cleanup function.

So the right way to stop an app is not to dispatch null but to dispatch undefined. Not sure wether that makes a difference (can’t easily try at the moment)

zaceno avatar Mar 06 '23 11:03 zaceno

@zaceno stopping app using undefined gives the same error: "TypeError: Cannot read properties of undefined (reading 'tag')"

sergey-shpak avatar Mar 06 '23 20:03 sergey-shpak

Could you make a pen with your code?

jorgebucaran avatar Mar 06 '23 23:03 jorgebucaran

@jorgebucaran https://codepen.io/sergey-shpak/pen/dyqVbYZ (errors in console section)

sergey-shpak avatar Mar 07 '23 13:03 sergey-shpak