From 112d15b20d45466d7e9d47f6b75477b9eaf5dd1f Mon Sep 17 00:00:00 2001 From: Sean Parsons Date: Tue, 22 Oct 2024 14:39:39 +0100 Subject: [PATCH] fix(canvas) Tweaks from PR feedback. - Speed improvement to `projectContentsSameForRefreshRequire`. - Remove unused code. --- editor/src/components/canvas/canvas-utils.ts | 4 ++++ editor/src/components/editor/import-utils.ts | 12 +----------- 2 files changed, 5 insertions(+), 11 deletions(-) diff --git a/editor/src/components/canvas/canvas-utils.ts b/editor/src/components/canvas/canvas-utils.ts index c4115943e35f..a40fa5ee34b2 100644 --- a/editor/src/components/canvas/canvas-utils.ts +++ b/editor/src/components/canvas/canvas-utils.ts @@ -2200,6 +2200,10 @@ export function projectContentsSameForRefreshRequire( } else { for (const [filename, oldProjectTree] of Object.entries(oldProjectContents)) { const newProjectTree = newProjectContents[filename] + // No need to check these further if they have the same reference. + if (oldProjectTree === newProjectTree) { + continue + } // If the file can't be found in the other tree, the imports are not the same. if (newProjectTree == null) { return false diff --git a/editor/src/components/editor/import-utils.ts b/editor/src/components/editor/import-utils.ts index 417c17d9da5f..b9971ac38b3c 100644 --- a/editor/src/components/editor/import-utils.ts +++ b/editor/src/components/editor/import-utils.ts @@ -31,7 +31,7 @@ import type { NodeModules, } from '../../core/shared/project-file-types' import { importAlias, importDetails, importsResolution } from '../../core/shared/project-file-types' -import { walkContentsTreeForParseSuccess, type ProjectContentTreeRoot } from '../assets' +import type { ProjectContentTreeRoot } from '../assets' import type { BuiltInDependencies } from '../../core/es-modules/package-manager/built-in-dependencies-list' import { withUnderlyingTarget } from './store/editor-state' import * as EP from '../../core/shared/element-path' @@ -366,13 +366,3 @@ function removeImportDetails( importedFromWithin: importedFromWithin, } } - -export function getProjectImports(projectContents: ProjectContentTreeRoot): { - [filename: string]: Imports -} { - let result: { [filename: string]: Imports } = {} - walkContentsTreeForParseSuccess(projectContents, (filePath, parseSuccess) => { - result[filePath] = parseSuccess.imports - }) - return result -}