preactjs / signals

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

`@preact/signals-react-transform` unresolved `@trackSignals ` #438

Closed XantreDev closed 7 months ago

XantreDev commented 8 months ago

If we are using @trackSignals directive - component can be untransformed without aware. Incorrect: image Correct: image

I think this behaviour will be confusing for transform users, transform should throw error, at least, if cannot handle @trackSignals.

Proposal:

Probably transform can also adapt more common directives pattern: use client, show source, worklet. Maybe something like use signals.

const Counter = () => {
  'use signals';

  return <p>{sig.value}</p>
}

This syntax can be less confusing in terms of components wrapped in hocs

XantreDev commented 8 months ago

Also I have issue that rollup + esbuild clears this comments while bundling. This can be footgun for library authors Esbuild is not supporting keeping comments for example: https://github.com/evanw/esbuild/issues/1439

andrewiggins commented 7 months ago

I believe PR #441 fixes the issue mentioned at the top. Functions wrapped in higher-order functions are supported. For example:

/** @trackSignals */
const C = memo(() => <div>{signal.value}</div>);

If you have an issue/concern with using rollup, etc. let's open a separate issue to discuss that.