avyvar's picture
Add Vite Selfbench 27-task evaluation
8579f8a verified
Raw History Blame Contribute Delete
3.58 kB
diff --git a/playground/dynamic-import/__tests__/dynamic-import.spec.ts b/playground/dynamic-import/__tests__/dynamic-import.spec.ts
index 384f41902..2008aef5b 100644
--- a/playground/dynamic-import/__tests__/dynamic-import.spec.ts
+++ b/playground/dynamic-import/__tests__/dynamic-import.spec.ts
@@ -135,6 +135,19 @@ test('should work with load ../ and contain itself directory', async () => {
.toMatch('dynamic-import-nested-self-content')
})
+// #22700: nested `import('a').then(() => import('b'))` where `a` has a CSS
+// side-effect dep — the outer import's CSS must still be loaded in build output
+test('should load css of nested dynamic import', async () => {
+ await expect
+ .poll(() => page.textContent('.then-css-outer'))
+ .toMatch('then-css-outer')
+ await expect.poll(() => getColor('.then-css-outer')).toBe('red')
+ await expect
+ .poll(() => page.textContent('.then-css-inner'))
+ .toMatch('then-css-inner')
+ await expect.poll(() => getColor('.then-css-inner')).toBe('green')
+})
+
test('should work a load path that contains parentheses.', async () => {
await expect
.poll(() =>
diff --git a/playground/dynamic-import/index.html b/playground/dynamic-import/index.html
index 1289efc3e..a5a0832ba 100644
--- a/playground/dynamic-import/index.html
+++ b/playground/dynamic-import/index.html
@@ -45,6 +45,9 @@
<div class="dynamic-import-nested-self"></div>
+<div class="then-css-outer">todo</div>
+<div class="then-css-inner">todo</div>
+
<script type="module" src="./nested/index.js"></script>
<script type="module" src="./(app)/nest/index.js"></script>
<style>
diff --git a/playground/dynamic-import/nested/index.js b/playground/dynamic-import/nested/index.js
index 6520e1f5a..c6e9ee406 100644
--- a/playground/dynamic-import/nested/index.js
+++ b/playground/dynamic-import/nested/index.js
@@ -201,4 +201,13 @@ import(`../nested/static.js`).then((mod) => {
text('.dynamic-import-static', mod.self)
})
+// #22700: in a nested `import().then(() => import())`, the outer import's CSS
+// dep used to be dropped to `void 0` in the build output, orphaning the CSS.
+import('./then-css/outer.js').then((outerMod) => {
+ text('.then-css-outer', outerMod.outer)
+ return import('./then-css/inner.js').then((innerMod) => {
+ text('.then-css-inner', innerMod.inner)
+ })
+})
+
console.log('index.js')
diff --git a/playground/dynamic-import/nested/then-css/inner.css b/playground/dynamic-import/nested/then-css/inner.css
new file mode 100644
index 000000000..9855e17de
--- /dev/null
+++ b/playground/dynamic-import/nested/then-css/inner.css
@@ -0,0 +1,3 @@
+.then-css-inner {
+ color: #008000;
+}
diff --git a/playground/dynamic-import/nested/then-css/inner.js b/playground/dynamic-import/nested/then-css/inner.js
new file mode 100644
index 000000000..01624aa99
--- /dev/null
+++ b/playground/dynamic-import/nested/then-css/inner.js
@@ -0,0 +1,2 @@
+import './inner.css'
+export const inner = 'then-css-inner'
diff --git a/playground/dynamic-import/nested/then-css/outer.css b/playground/dynamic-import/nested/then-css/outer.css
new file mode 100644
index 000000000..f829bca5b
--- /dev/null
+++ b/playground/dynamic-import/nested/then-css/outer.css
@@ -0,0 +1,3 @@
+.then-css-outer {
+ color: #ff0000;
+}
diff --git a/playground/dynamic-import/nested/then-css/outer.js b/playground/dynamic-import/nested/then-css/outer.js
new file mode 100644
index 000000000..4e1516b99
--- /dev/null
+++ b/playground/dynamic-import/nested/then-css/outer.js
@@ -0,0 +1,2 @@
+import './outer.css'
+export const outer = 'then-css-outer'