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

handle circular dependencies in dynamic imports #5619

Merged
merged 2 commits into from
Jul 19, 2022
Merged
Show file tree
Hide file tree
Changes from all 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
5 changes: 5 additions & 0 deletions .changeset/eleven-crews-knock.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@sveltejs/kit': patch
---

Handle circular dependencies in dynamic imports
7 changes: 6 additions & 1 deletion packages/kit/src/vite/build/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,9 @@ export async function create_build(config) {
* @param {boolean} add_dynamic_css
*/
export function find_deps(manifest, entry, add_dynamic_css) {
/** @type {Set<string>} */
const seen = new Set();

/** @type {Set<string>} */
const imports = new Set();

Expand All @@ -46,9 +49,11 @@ export function find_deps(manifest, entry, add_dynamic_css) {
* @param {boolean} add_js
*/
function traverse(file, add_js) {
if (seen.has(file)) return;
seen.add(file);

const chunk = manifest[file];

if (imports.has(chunk.file)) return;
if (add_js) imports.add(chunk.file);

if (chunk.css) {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
export async function is_even(num) {
const { is_odd } = await import('./_is_odd.js');
if (num === 0) return true;
return is_odd(num - 1);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
export async function is_odd(num) {
const { is_even } = await import('./_is_even.js');
if (num === 1) return true;
return is_even(num - 1);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<script>
import { onMount } from 'svelte';

onMount(async () => {
const { is_even } = await import('./_is_even.js');
console.log(is_even(5));
});
</script>