Skip to content

Breaking change in useComputed #789

@lucacasonato

Description

@lucacasonato

Environment

  • I am using @preact/signals-core
  • I am using @preact/signals

Describe the bug

The change made in #754 broke our application after upgrade. I don't think it was previously part of the signals contract that a computed could be recomputed at any time, even if a dependency signal did not change. This means that computeds that rely on the fact that they only run once (ones used as useSignalEffect with an output) do not work correctly anymore because they get rerun too often.

I would advocate to revert this change. If you need to rerun the computed function on prop changes, you should make your props signals. You cannot do that with a change of the external API, you can do it using useEffect and useSignal.

The specific thing that broke for us was a useComputed that returns an interior mutable object which was now being recreated every re-render.

Because this was a breaking change, I think this should not have shipped in a minor or patch.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions