Skip to content

Commit ed29499

Browse files
committed
fix(BlockList): render items to wrapper instead to portal direcly to improve reconcilation
fix(useGraphEvent): use useEffect to listen graph-event fix(useSignal): useLayoutEffect to faster get signal-value
1 parent e3348d3 commit ed29499

File tree

3 files changed

+8
-7
lines changed

3 files changed

+8
-7
lines changed

src/react-components/BlocksList.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -119,14 +119,14 @@ export const BlocksList = memo(function BlocksList({ renderBlock, graphObject }:
119119
}, [graphObject, scheduleListUpdate]);
120120

121121
return (
122-
<>
122+
<div>
123123
{graphState === GraphState.READY &&
124124
cameraScaleLevel === ECameraScaleLevel.Detailed &&
125125
blockStates.map((blockState) => {
126126
return (
127127
<Block key={blockState.id} renderBlock={renderBlock} graphObject={graphObject} blockState={blockState} />
128128
);
129129
})}
130-
</>
130+
</div>
131131
);
132132
});

src/react-components/hooks/useGraphEvents.ts

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { useLayoutEffect, useMemo, useRef } from "react";
1+
import { useEffect, useLayoutEffect, useMemo, useRef } from "react";
22

33
import { Graph } from "../../graph";
44
import { GraphEventsDefinitions, UnwrapGraphEvents, UnwrapGraphEventsDetail } from "../../graphEvents";
@@ -48,10 +48,11 @@ export function useGraphEvent<Event extends keyof GraphEventsDefinitions>(
4848
lastEventRef.current = e;
4949
fn();
5050
});
51-
useLayoutEffect(() => {
51+
useEffect(() => {
5252
if (!graph) return undefined;
5353
return graph.on(event, onEvent);
5454
}, [graph, event, onEvent]);
55+
5556
useLayoutEffect(() => {
5657
return () => {
5758
fn.cancel?.();
@@ -60,7 +61,7 @@ export function useGraphEvent<Event extends keyof GraphEventsDefinitions>(
6061
}
6162

6263
export function useGraphEvents(graph: Graph | null, events: Partial<TGraphEventCallbacks>): void {
63-
useLayoutEffect(() => {
64+
useEffect(() => {
6465
if (!graph) return undefined;
6566

6667
const unsubscribe = [];

src/react-components/hooks/useSignal.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
1-
import { useEffect, useState } from "react";
1+
import { useLayoutEffect, useState } from "react";
22

33
import type { Signal } from "@preact/signals-core";
44

55
export function useSignal<T>(signal: Signal<T>) {
66
const [state, setState] = useState(signal.value);
7-
useEffect(() => {
7+
useLayoutEffect(() => {
88
return signal.subscribe(setState);
99
}, [signal]);
1010
return state;

0 commit comments

Comments
 (0)