File tree Expand file tree Collapse file tree 1 file changed +20
-0
lines changed
src/components/editor2/action Expand file tree Collapse file tree 1 file changed +20
-0
lines changed Original file line number Diff line number Diff line change @@ -61,9 +61,19 @@ const activeActionLocationAtom = atom(
61
61
} ,
62
62
)
63
63
64
+ // Defer initializing the map until it's visible. It's handled via atoms instead of
65
+ // component states to avoid unnecessary rerenders when the map has already been initialized.
66
+ const initializedAtom = atom ( false )
67
+ const shouldInitializeAtom = atom (
68
+ ( get ) =>
69
+ ! get ( initializedAtom ) && get ( editorAtoms . selectorPanelMode ) === 'map' ,
70
+ )
71
+
64
72
export const LevelMap : FC < LevelMapProps > = memo ( ( { className } ) => {
65
73
const t = useTranslation ( )
66
74
const { data : levels } = useLevels ( )
75
+ const [ initialized , setInitialized ] = useAtom ( initializedAtom )
76
+ const shouldInitialize = useAtomValue ( shouldInitializeAtom )
67
77
const stageName = useAtomValue ( stageNameAtom )
68
78
const [ activeLocation , setActiveLocation ] = useAtom ( activeActionLocationAtom )
69
79
const level = useMemo (
@@ -120,6 +130,16 @@ export const LevelMap: FC<LevelMapProps> = memo(({ className }) => {
120
130
}
121
131
} , [ iframeWindow ] )
122
132
133
+ useEffect ( ( ) => {
134
+ if ( shouldInitialize ) {
135
+ setInitialized ( true )
136
+ }
137
+ } , [ shouldInitialize , setInitialized ] )
138
+
139
+ if ( ! initialized ) {
140
+ return null
141
+ }
142
+
123
143
return (
124
144
< div className = { clsx ( 'relative flex-grow' , className ) } >
125
145
{ level && (
You can’t perform that action at this time.
0 commit comments