Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Check for existing scope on possible cyclic dependencies #4292

Merged
merged 1 commit into from
Oct 3, 2023

Conversation

Rheeseyb
Copy link
Contributor

@Rheeseyb Rheeseyb commented Oct 2, 2023

Problem:
Whilst evaluating a project inside the canvas, when we reach an import statement that has already been resolved we assume that it is a cyclic dependency, and fall back to the default import handling, meaning we won't wrap the imported components and therefore can't focus and edit them.

This can be shown by having a file A import file B, and then have multiple files import file A, which is shown here - in this project, the Text component cannot be focused, as the import statement import { Text } from '/src/text' inside card.js is evaluated twice. To see that working on this branch, test the project here

Fix:
Rather than immediately assume that we have hit upon a cyclic dependency that we can't handle, we now keep a reference to the scope created by each import, and return that if it exists. If no such scope exists (and we have already resolved that import), then we will fall back to the default import handling.

@github-actions
Copy link
Contributor

github-actions bot commented Oct 2, 2023

Try me

@relativeci
Copy link

relativeci bot commented Oct 2, 2023

Job #8358: Bundle Size — 62.78MiB (~+0.01%).

d60d85f(current) vs 5957b21 master#8355(baseline)

Warning

Bundle contains 64 duplicate packages - View duplicate packages

Bundle metrics (1 change)
                 Current
Job #8358
     Baseline
Job #8355
Initial JS 35.05MiB(~+0.01%) 35.05MiB
Initial CSS 0B 0B
Cache Invalidation 18.39% 18.39%
Chunks 27 27
Assets 31 31
Modules 3973 3973
Duplicate Modules 424 424
Duplicate Code 30.9% 30.9%
Packages 409 409
Duplicate Packages 64 64
Bundle size by type (1 change)
                 Current
Job #8358
     Baseline
Job #8355
CSS 0B 0B
Fonts 0B 0B
HTML 11.43KiB 11.43KiB
IMG 0B 0B
JS 62.77MiB (~+0.01%) 62.77MiB
Media 0B 0B
Other 0B 0B

View job #8358 reportView fix/multiple-import-handling branch activity

return existingScope == null ? left(msg) : right(existingScope)
},
(resolvedFilePath) => {
resolvedFromThisOrigin[toImport] = null // We use null as a marker to indicate that we have started resolving, but not completed yet
Copy link
Contributor

@balazsbajorics balazsbajorics Oct 2, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can't we use some other marker like 'started-resolving'? I think the !== undefined (from above) is very unexpressive, and the shape of the code would stay the same

@github-actions
Copy link
Contributor

github-actions bot commented Oct 2, 2023

Performance test results:
(Chart1)
(Chart2)

@Rheeseyb Rheeseyb merged commit 90a1f6d into master Oct 3, 2023
16 checks passed
@Rheeseyb Rheeseyb deleted the fix/multiple-import-handling branch October 3, 2023 09:25
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants