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

fix(v6): fix maximum call stack error in ModuleRunner.isCurcularImport #17740

Merged
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 10 additions & 2 deletions packages/vite/src/module-runner/runner.ts
Original file line number Diff line number Diff line change
Expand Up @@ -162,8 +162,16 @@ export class ModuleRunner {
return false
}

private isCurcularImport(importers: Set<string>, moduleId: string) {
private isCurcularImport(
Copy link
Member

Choose a reason for hiding this comment

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

@hi-ogawa would you also update the name to be isCircularImport ?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Oh, didn't notice. There's one more above isCurcularModule. I fixed that too.

importers: Set<string>,
moduleId: string,
visited = new Set<string>(),
) {
for (const importer of importers) {
if (visited.has(importer)) {
continue
}
visited.add(importer)
if (importer === moduleId) {
return true
}
Expand All @@ -172,7 +180,7 @@ export class ModuleRunner {
) as Required<ModuleCache>
if (
mod.importers.size &&
this.isCurcularImport(mod.importers, moduleId)
this.isCurcularImport(mod.importers, moduleId, visited)
) {
return true
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export function someAction() {}
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
export default async function main() {
await import("./entry.js");
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
export async function setupCyclic() {
const mod = await import("./entry-cyclic.js");
await mod.default();
}

export async function importAction(id) {
return await import(/* @vite-ignore */ id);
}
Original file line number Diff line number Diff line change
Expand Up @@ -218,4 +218,16 @@ describe('module runner initialization', async () => {
expect(posix.join(root, './fixtures')).toBe(dirname)
}
})

it(`no maximum call stack error ModuleRunner.isCurcularImport`, async ({
runner,
}) => {
// entry.js ⇔ entry-cyclic.js
// ⇓
// action.js
const mod = await runner.import('/fixtures/cyclic/entry')
await mod.setupCyclic()
const action = await mod.importAction('/fixtures/cyclic/action')
expect(action).toBeDefined()
})
})
Loading