Skip to content

Commit 36213b9

Browse files
authored
feat(import): early break on error (#6604)
This PR breaks early when there is a requirement check error (for example a TS project) - without fetching dependencies or dispatching the results to the project. For example a Next TS project - note the dependencies are not fetched and the project contents are not updated: <video src="https://github.com/user-attachments/assets/6ef4e75a-1659-4219-b7e0-d94471a88f57"></video> **Manual Tests:** I hereby swear that: - [X] I opened a hydrogen project and it loaded - [X] I could navigate to various routes in Play mode
1 parent 8f9354e commit 36213b9

File tree

3 files changed

+25
-10
lines changed

3 files changed

+25
-10
lines changed

editor/src/components/editor/import-wizard/components.tsx

+5-2
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,11 @@ export function OperationLine({ operation }: { operation: ImportOperation }) {
2929

3030
const [childrenShown, serChildrenShown] = React.useState(false)
3131
const shouldShowChildren = React.useMemo(
32-
() => childrenShown || operation.timeDone == null,
33-
[childrenShown, operation.timeDone],
32+
() =>
33+
childrenShown ||
34+
operation.timeDone == null ||
35+
operation.result == ImportOperationResult.Error,
36+
[childrenShown, operation.timeDone, operation.result],
3437
)
3538
const hasChildren = React.useMemo(
3639
() => operation.children != null && operation.children.length > 0,

editor/src/core/shared/github/operations/load-branch.ts

+13-6
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,10 @@ import {
4242
notifyOperationStarted,
4343
startImportProcess,
4444
} from '../../import/import-operation-service'
45-
import { resetRequirementsResolutions } from '../../import/proejct-health-check/utopia-requirements-service'
45+
import {
46+
RequirementResolutionResult,
47+
resetRequirementsResolutions,
48+
} from '../../import/proejct-health-check/utopia-requirements-service'
4649
import { checkAndFixUtopiaRequirements } from '../../import/proejct-health-check/check-utopia-requirements'
4750
import { ImportOperationResult } from '../../import/import-operation-types'
4851

@@ -171,8 +174,12 @@ export const updateProjectWithBranchContent =
171174
notifyOperationFinished(dispatch, { type: 'parseFiles' }, ImportOperationResult.Success)
172175

173176
resetRequirementsResolutions(dispatch)
177+
const { fixedProjectContents, result: requirementResolutionResult } =
178+
checkAndFixUtopiaRequirements(dispatch, parseResults)
174179

175-
const parsedProjectContents = checkAndFixUtopiaRequirements(dispatch, parseResults)
180+
if (requirementResolutionResult === RequirementResolutionResult.Critical) {
181+
return []
182+
}
176183

177184
// Update the editor with everything so that if anything else fails past this point
178185
// there's no loss of data from the user's perspective.
@@ -185,19 +192,19 @@ export const updateProjectWithBranchContent =
185192
branchName,
186193
true,
187194
),
188-
updateProjectContents(parsedProjectContents),
189-
updateBranchContents(parsedProjectContents),
195+
updateProjectContents(fixedProjectContents),
196+
updateBranchContents(fixedProjectContents),
190197
truncateHistory(),
191198
],
192199
'everyone',
193200
)
194201

195202
const componentDescriptorFiles =
196-
getAllComponentDescriptorFilePaths(parsedProjectContents)
203+
getAllComponentDescriptorFilePaths(fixedProjectContents)
197204

198205
// If there's a package.json file, then attempt to load the dependencies for it.
199206
let dependenciesPromise: Promise<void> = Promise.resolve()
200-
const packageJson = packageJsonFileFromProjectContents(parsedProjectContents)
207+
const packageJson = packageJsonFileFromProjectContents(fixedProjectContents)
201208
if (packageJson != null && isTextFile(packageJson)) {
202209
notifyOperationStarted(dispatch, { type: 'refreshDependencies' })
203210
dependenciesPromise = refreshDependencies(

editor/src/core/shared/import/proejct-health-check/check-utopia-requirements.ts

+7-2
Original file line numberDiff line numberDiff line change
@@ -5,26 +5,31 @@ import type { EditorDispatch } from '../../../../components/editor/action-types'
55
import CheckPackageJson from './requirements/requirement-package-json'
66
import CheckLanguage from './requirements/requirement-language'
77
import CheckReactVersion from './requirements/requirement-react'
8+
import { RequirementResolutionResult } from './utopia-requirements-types'
89
import type { ProjectRequirement, RequirementCheck } from './utopia-requirements-types'
910
import { notifyCheckingRequirement, notifyResolveRequirement } from './utopia-requirements-service'
1011
import CheckStoryboard from './requirements/requirement-storyboard'
1112

1213
export function checkAndFixUtopiaRequirements(
1314
dispatch: EditorDispatch,
1415
parsedProjectContents: ProjectContentTreeRoot,
15-
): ProjectContentTreeRoot {
16+
): { result: RequirementResolutionResult; fixedProjectContents: ProjectContentTreeRoot } {
1617
const checks: Record<ProjectRequirement, RequirementCheck> = {
1718
storyboard: new CheckStoryboard(),
1819
packageJsonEntries: new CheckPackageJson(),
1920
language: new CheckLanguage(),
2021
reactVersion: new CheckReactVersion(),
2122
}
2223
let projectContents = parsedProjectContents
24+
let result: RequirementResolutionResult = RequirementResolutionResult.Found
2325
// iterate over all checks, updating the project contents as we go
2426
for (const [name, check] of Object.entries(checks)) {
2527
const checkName = name as ProjectRequirement
2628
notifyCheckingRequirement(dispatch, checkName, check.getStartText())
2729
const checkResult = check.check(projectContents)
30+
if (checkResult.resolution === RequirementResolutionResult.Critical) {
31+
result = RequirementResolutionResult.Critical
32+
}
2833
notifyResolveRequirement(
2934
dispatch,
3035
checkName,
@@ -34,7 +39,7 @@ export function checkAndFixUtopiaRequirements(
3439
)
3540
projectContents = checkResult.newProjectContents ?? projectContents
3641
}
37-
return projectContents
42+
return { result: result, fixedProjectContents: projectContents }
3843
}
3944

4045
export function getPackageJson(

0 commit comments

Comments
 (0)