File size: 3,582 Bytes
8579f8a
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
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'