atlassian / react-sweet-state

Shared state management solution for React
https://atlassian.github.io/react-sweet-state/
MIT License
871 stars 55 forks source link

Uncaught TypeError: Cannot read properties of null (reading 'unsubscribe') #216

Closed AjithKumarvm closed 1 year ago

AjithKumarvm commented 1 year ago

File: /node_modules/react-sweet-state/lib/esm/components/hook.js

        // On component unmount we unsubscribe to storeState updates
        subscription.unsubscribe();
        subscription = null;
      };

Its a runtime error. happens randomly. version "react-sweet-state": "2.6.0". Critical bug, crashes the entire website I am using react-sweet-state with react": "18.2.0" and "vite": "^4.2.1"

AjithKumarvm commented 1 year ago

I would have raised a PR to fix this issue, but couldn't find this particular line of code in the src folder of react-sweet-state.

albertogasparin commented 1 year ago

Can you try upgrading to latest, v2.7.x ? Those lines of code do not exist anymore

AjithKumarvm commented 1 year ago

You are right! @albertogasparin. I checked the source code of v2.6.0. I found this line inside hook.js. But its not found in further releases. I will upgrade the package to latest and test it.

AjithKumarvm commented 1 year ago

Hi @albertogasparin. I cannot use 2.7.1 since it has another bug. Focus on a controlled input text box which has some text already, place the cursor in between words and on typing the cursor moves to the end of the text abruptly.

AjithKumarvm commented 1 year ago

2.7.1 has this issue precisely: https://github.com/atlassian/react-sweet-state/issues/178

albertogasparin commented 1 year ago

Ok, that is a different limitation tho (affecting 2.6.0 too). Happy to keep talking about solutions on https://github.com/atlassian/react-sweet-state/issues/178