luisherranz / deepsignal

DeepSignal 🧶 - Preact signals, but using regular JavaScript objects
MIT License
210 stars 5 forks source link

useSignalEffect won't fire. #67

Closed saurabswaarm closed 2 months ago

saurabswaarm commented 2 months ago

I'm unable to get use signal effect to fire in my React Application if I follow the following set up.(adjRow is the deep signal.)


useSignalEffect(()=>{
    if(finalTableRows.length > 0 && adjRow.action=== 'adding'){
      // some code here
      adjRow.reset();
    }
  })

However I can get the useSignalEffect to fire if instead I assign adjRow.action to a variable.

useSignalEffect(()=>{
    const action = adjRow.action 
    debugger;
    if(finalTableRows.length > 0 && action=== 'adding'){
     // some code here
      adjRow.reset();
    }
  })

is this something to do with the way signals / reactivity works ?

Please not i am using / have tried babel transform and the useSignals hook to wire my react appication in.


Versions

luisherranz commented 2 months ago

Could you please reproduce the error using StackBlitz so I can take a look? You can fork this template to get started.

saurabswaarm commented 2 months ago

Hi, here's the code, but it seems to work fine. I can access the signal without having an assignment operator. I can't reproduce my error means it has something to do with my set up.

https://stackblitz.com/edit/vitejs-vite-cyswtz?file=src%2Fmain.jsx

But in my codebase we are using webpack and babel also in the babel trasform i have set it to manual,

{
    "presets": [
        "@babel/preset-env",
        "@babel/preset-react"
    ],
    "plugins": [
        ["@babel/transform-runtime", {
          "regenerator": true
        }],
        ["module:@preact/signals-react-transform", {
          "mode":"manual"
        }]
      ]
}

as auto gives me this error

 Warning: Invalid hook call. Hooks can only be called inside of the body of a function component.
luisherranz commented 2 months ago

Have you checked if the problem happens only with deepsignal or if it also occurs with normal signals?

saurabswaarm commented 2 months ago

now that i test it out with just preact, it happens with preact too. Doesn't matter if I use the useSignals hook or if i annotate my components like

/**
 * @useSignals
 */
const Component = (props) => {


More info. "webpack": "^5.51.1", "webpack-cli": "^4.7.2", "webpack-dev-server": "^3.11.2" "babel-loader": "^8.2.2", "@babel/core": "^7.15.0",

Another interesting observation is our node is locked in at v14.

I think I'll file an issue over at preact as well. We can close this because this is clearly not an issue with deep signals.

luisherranz commented 2 months ago

We can close this because this is clearly not an issue with deep signals.

Alright, I'll close it then. Feel free to reopen it if you find that the issue is indeed related to deepsignal.