From 9253c6546a4108356fb92b01bbfabaf6fcbb67c4 Mon Sep 17 00:00:00 2001 From: Shusui MOYATANI Date: Wed, 17 Jan 2024 12:20:23 +0900 Subject: [PATCH] fix: use createRoot for signals outside components --- src/hooks/useMessageBus.ts | 6 ++++-- src/hooks/useModalState.ts | 4 ++-- src/nostr/usePubkey.ts | 4 ++-- 3 files changed, 8 insertions(+), 6 deletions(-) diff --git a/src/hooks/useMessageBus.ts b/src/hooks/useMessageBus.ts index 9491167..b595829 100644 --- a/src/hooks/useMessageBus.ts +++ b/src/hooks/useMessageBus.ts @@ -1,4 +1,4 @@ -import { createSignal, createMemo, onMount, type Signal, onCleanup } from 'solid-js'; +import { createRoot, createSignal, createMemo, onMount, type Signal, onCleanup } from 'solid-js'; export type UseRequestMessageProps = { id: string; @@ -19,7 +19,9 @@ export type MessageChannelResponse = // eslint-disable-next-line @typescript-eslint/no-explicit-any | { requestId: string; ok: false; error: any }; -const [channels, setChannels]: Signal> = createSignal({}); +const [channels, setChannels]: Signal> = createRoot(() => + createSignal({}), +); const registerChannelIfNotExist = (id: string) => { if (channels()[id] == null) { diff --git a/src/hooks/useModalState.ts b/src/hooks/useModalState.ts index b28839a..c79018e 100644 --- a/src/hooks/useModalState.ts +++ b/src/hooks/useModalState.ts @@ -1,4 +1,4 @@ -import { createSignal } from 'solid-js'; +import { createRoot, createSignal } from 'solid-js'; type ModalState = | { type: 'Login' } @@ -9,7 +9,7 @@ type ModalState = | { type: 'About' } | { type: 'Closed' }; -const [modalState, setModalState] = createSignal({ type: 'Closed' }); +const [modalState, setModalState] = createRoot(() => createSignal({ type: 'Closed' })); const useModalState = () => { const showLogin = () => { diff --git a/src/nostr/usePubkey.ts b/src/nostr/usePubkey.ts index cac7f94..fc39f6c 100644 --- a/src/nostr/usePubkey.ts +++ b/src/nostr/usePubkey.ts @@ -1,8 +1,8 @@ import '@/types/nostr.d'; -import { createSignal, onMount, type Accessor } from 'solid-js'; +import { createRoot, createSignal, onMount, type Accessor } from 'solid-js'; let asking = false; -const [pubkey, setPubkey] = createSignal(undefined); +const [pubkey, setPubkey] = createRoot(() => createSignal(undefined)); // TODO 失敗したときに通知等を表示したい const usePubkey = (): Accessor => {