fix: use createRoot for signals outside components

This commit is contained in:
Shusui MOYATANI
2024-01-17 12:20:23 +09:00
parent 2d9c1ef652
commit 9253c6546a
3 changed files with 8 additions and 6 deletions

View File

@@ -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<T> =
// eslint-disable-next-line @typescript-eslint/no-explicit-any
| { requestId: string; ok: false; error: any };
const [channels, setChannels]: Signal<Record<string, MessageChannel>> = createSignal({});
const [channels, setChannels]: Signal<Record<string, MessageChannel>> = createRoot(() =>
createSignal({}),
);
const registerChannelIfNotExist = (id: string) => {
if (channels()[id] == null) {

View File

@@ -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<ModalState>({ type: 'Closed' });
const [modalState, setModalState] = createRoot(() => createSignal<ModalState>({ type: 'Closed' }));
const useModalState = () => {
const showLogin = () => {

View File

@@ -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<string | undefined>(undefined);
const [pubkey, setPubkey] = createRoot(() => createSignal<string | undefined>(undefined));
// TODO 失敗したときに通知等を表示したい
const usePubkey = (): Accessor<string | undefined> => {