Skip to content

Commit 9de3435

Browse files
authored
handle circular dependencies in dynamic imports (#5619)
* handle circular dependencies in dynamic imports - closes #5399 * add test
1 parent 8191720 commit 9de3435

File tree

5 files changed

+29
-1
lines changed

5 files changed

+29
-1
lines changed

.changeset/eleven-crews-knock.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'@sveltejs/kit': patch
3+
---
4+
5+
Handle circular dependencies in dynamic imports

packages/kit/src/vite/build/utils.js

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,9 @@ export async function create_build(config) {
3535
* @param {boolean} add_dynamic_css
3636
*/
3737
export function find_deps(manifest, entry, add_dynamic_css) {
38+
/** @type {Set<string>} */
39+
const seen = new Set();
40+
3841
/** @type {Set<string>} */
3942
const imports = new Set();
4043

@@ -46,9 +49,11 @@ export function find_deps(manifest, entry, add_dynamic_css) {
4649
* @param {boolean} add_js
4750
*/
4851
function traverse(file, add_js) {
52+
if (seen.has(file)) return;
53+
seen.add(file);
54+
4955
const chunk = manifest[file];
5056

51-
if (imports.has(chunk.file)) return;
5257
if (add_js) imports.add(chunk.file);
5358

5459
if (chunk.css) {
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
export async function is_even(num) {
2+
const { is_odd } = await import('./_is_odd.js');
3+
if (num === 0) return true;
4+
return is_odd(num - 1);
5+
}
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
export async function is_odd(num) {
2+
const { is_even } = await import('./_is_even.js');
3+
if (num === 1) return true;
4+
return is_even(num - 1);
5+
}
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
<script>
2+
import { onMount } from 'svelte';
3+
4+
onMount(async () => {
5+
const { is_even } = await import('./_is_even.js');
6+
console.log(is_even(5));
7+
});
8+
</script>

0 commit comments

Comments
 (0)