Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cannot read properties of null (reading 'length') #1111

Open
sergey-shpak opened this issue Mar 5, 2023 · 5 comments
Open

Cannot read properties of null (reading 'length') #1111

sergey-shpak opened this issue Mar 5, 2023 · 5 comments
Labels
bug Something isn't working

Comments

@sergey-shpak
Copy link
Contributor

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)

@jorgebucaran jorgebucaran added the bug Something isn't working label Mar 6, 2023
@sergey-shpak
Copy link
Contributor Author

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')"

@zaceno
Copy link
Contributor

zaceno commented Mar 6, 2023

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)

@sergey-shpak
Copy link
Contributor Author

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

@jorgebucaran
Copy link
Owner

Could you make a pen with your code?

@sergey-shpak
Copy link
Contributor Author

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

3 participants