Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/odd-tigers-remember.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@preact/signals": patch
---

Fix prefresh HMR not working with `useSignal`.
9 changes: 4 additions & 5 deletions packages/preact/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { options, Component, isValidElement, Fragment } from "preact";
import { useRef, useMemo, useEffect } from "preact/hooks";
import { useRef, useMemo, useEffect, useState } from "preact/hooks";
import {
signal,
computed,
Expand Down Expand Up @@ -387,10 +387,9 @@ Component.prototype.shouldComponentUpdate = function (
export function useSignal<T>(value: T, options?: SignalOptions<T>): Signal<T>;
export function useSignal<T = undefined>(): Signal<T | undefined>;
export function useSignal<T>(value?: T, options?: SignalOptions<T>) {
return useMemo(
() => signal<T | undefined>(value, options as SignalOptions),
[]
);
return useState(() =>

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Clever!

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Per a chat with @JoviDeCroock, would using useState prevent the SCU optimizations (which bail early if there are useState usages in a component)?

signal<T | undefined>(value, options as SignalOptions)
)[0];
}

export function useComputed<T>(compute: () => T, options?: SignalOptions<T>) {
Expand Down