preactjs / signals

Manage state with style in every framework
https://preactjs.com/blog/introducing-signals/
MIT License
3.63k stars 88 forks source link

React-Signal text node binding not working when "@preact/signals" is imported #513

Closed gutentag2012 closed 4 months ago

gutentag2012 commented 4 months ago

The Code

import {signal} from "@preact/signals";
import {signal as signalReact} from "@preact/signals-react";

const someSignalFromALibrary = signal(0)
const count = signalReact(0)

function App() {
return (
    <button
      type="button"
      onClick={() => {
        count.value += 1;
      }}
    >
      count is {count}
    </button>
  );
}

Environment

I am using vite and the babel transform plugin within the react babel config of vite.

The Issue

When running the provided code the runtime error Uncaught TypeError: Cannot read properties of undefined (reading '__H') occurs. This is not the case when either:

  1. Removing the import from @preact/signals or
  2. Using an explicit binding for the count count is {count.value}

Notes

It is enough to have an import "@preact/signals" somewhere in the imports to result in this behavior, so there is probably some side effect to the import, that results in this behavior. I also tried importing the react signals package in a different file that is loaded before but that also does not resolve the issue.

XantreDev commented 4 months ago

@preact/signals - for preact @preact/signals-react - for react You can use only one at time

rschristian commented 4 months ago

Yep, please do read the instructions: https://github.com/preactjs/signals?tab=readme-ov-file#installation & https://github.com/preactjs/signals/blob/main/packages/react/README.md#react-integration