@@ -102,11 +102,14 @@ const renameModule = (id: string, moduleId: string, title: string) => async (
102102 dispatch : Function ,
103103 getState : Function ,
104104) => {
105- const modules = modulesSelector ( getState ( ) ) ;
105+ let modules = modulesSelector ( getState ( ) ) ;
106106 const module = modules [ moduleId ] ;
107107 const sandboxId = await dispatch ( maybeForkSandbox ( id ) ) ;
108108 const isForked = sandboxId !== id ;
109109
110+ // Modules have updated after fork
111+ modules = modulesSelector ( getState ( ) ) ;
112+
110113 const newModule = isForked
111114 ? getEquivalentModule ( module , values ( modules ) ) || module
112115 : module ;
@@ -135,12 +138,14 @@ const renameDirectory = (
135138 directoryId : string ,
136139 title : string ,
137140) => async ( dispatch : Function , getState : Function ) => {
138- const directories = directoriesSelector ( getState ( ) ) ;
141+ let directories = directoriesSelector ( getState ( ) ) ;
139142 const directory = directories [ directoryId ] ;
140143 const sandboxId = await dispatch ( maybeForkSandbox ( id ) ) ;
141-
142144 const isForked = id !== sandboxId ;
143145
146+ // Directories have updated after fork
147+ directories = directoriesSelector ( getState ( ) ) ;
148+
144149 const newDirectory = isForked
145150 ? getEquivalentDirectory ( directory , values ( directories ) ) || directory
146151 : directory ;
@@ -169,11 +174,14 @@ const moveModuleToDirectory = (
169174 moduleId : string ,
170175 directoryShortid : string ,
171176) => async ( dispatch : Function , getState : Function ) => {
172- const modules = modulesSelector ( getState ( ) ) ;
177+ let modules = modulesSelector ( getState ( ) ) ;
173178 const module = modules [ moduleId ] ;
174179 const sandboxId = await dispatch ( maybeForkSandbox ( id ) ) ;
175180 const isForked = sandboxId !== id ;
176181
182+ // Modules have updated after fork
183+ modules = modulesSelector ( getState ( ) ) ;
184+
177185 const newModule = isForked
178186 ? getEquivalentModule ( module , values ( modules ) ) || module
179187 : module ;
@@ -202,12 +210,14 @@ const moveDirectoryToDirectory = (
202210 directoryId : string ,
203211 parentId : string ,
204212) => async ( dispatch : Function , getState : Function ) => {
205- const directories = directoriesSelector ( getState ( ) ) ;
213+ let directories = directoriesSelector ( getState ( ) ) ;
206214 const directory = directories [ directoryId ] ;
207215 const sandboxId = await dispatch ( maybeForkSandbox ( id ) ) ;
208-
209216 const isForked = id !== sandboxId ;
210217
218+ // Directories have updated after fork
219+ directories = directoriesSelector ( getState ( ) ) ;
220+
211221 const newDirectory = isForked
212222 ? getEquivalentDirectory ( directory , values ( directories ) ) || directory
213223 : directory ;
@@ -237,11 +247,14 @@ const deleteModule = (id: string, moduleId: string) => async (
237247 dispatch : Function ,
238248 getState : Function ,
239249) => {
240- const modules = modulesSelector ( getState ( ) ) ;
250+ let modules = modulesSelector ( getState ( ) ) ;
241251 const module = modules [ moduleId ] ;
242252 const sandboxId = await dispatch ( maybeForkSandbox ( id ) ) ;
243253 const isForked = sandboxId !== id ;
244254
255+ // Modules have updated after fork
256+ modules = modulesSelector ( getState ( ) ) ;
257+
245258 const newModule = isForked
246259 ? getEquivalentModule ( module , values ( modules ) ) || module
247260 : module ;
@@ -268,12 +281,14 @@ const deleteDirectory = (id: string, directoryId: string) => async (
268281 dispatch : Function ,
269282 getState : Function ,
270283) => {
271- const directories = directoriesSelector ( getState ( ) ) ;
284+ let directories = directoriesSelector ( getState ( ) ) ;
272285 const directory = directories [ directoryId ] ;
273286 const sandboxId = await dispatch ( maybeForkSandbox ( id ) ) ;
274-
275287 const isForked = id !== sandboxId ;
276288
289+ // Directories have updated after fork
290+ directories = directoriesSelector ( getState ( ) ) ;
291+
277292 const newDirectory = isForked
278293 ? getEquivalentDirectory ( directory , values ( directories ) ) || directory
279294 : directory ;
@@ -362,11 +377,14 @@ const saveModuleCode = (id: string, moduleId: string) => async (
362377 dispatch : Function ,
363378 getState : Function ,
364379) => {
365- const modules = modulesSelector ( getState ( ) ) ;
380+ let modules = modulesSelector ( getState ( ) ) ;
366381 const module = modules [ moduleId ] ;
367382 const sandboxId = await dispatch ( maybeForkSandbox ( id ) ) ;
368383 const isForked = sandboxId !== id ;
369384
385+ // Modules have updated after fork
386+ modules = modulesSelector ( getState ( ) ) ;
387+
370388 const newModule = isForked
371389 ? getEquivalentModule ( module , values ( modules ) ) || module
372390 : module ;
0 commit comments