|
8 | 8 | KeepAlive, |
9 | 9 | Suspense, |
10 | 10 | type SuspenseProps, |
| 11 | + Teleport, |
11 | 12 | createCommentVNode, |
12 | 13 | h, |
13 | 14 | nextTick, |
@@ -2165,6 +2166,127 @@ describe('Suspense', () => { |
2165 | 2166 | await Promise.all(deps) |
2166 | 2167 | }) |
2167 | 2168 |
|
| 2169 | + test('should mount after suspense is resolved', async () => { |
| 2170 | + const target = nodeOps.createElement('div') |
| 2171 | + |
| 2172 | + const Async = defineAsyncComponent({ |
| 2173 | + render() { |
| 2174 | + return h('div', 'async') |
| 2175 | + }, |
| 2176 | + }) |
| 2177 | + |
| 2178 | + const Comp = { |
| 2179 | + setup() { |
| 2180 | + return () => |
| 2181 | + h(Suspense, null, { |
| 2182 | + default: h('div', null, [ |
| 2183 | + h(Async), |
| 2184 | + h(Teleport, { to: target }, h('div', 'teleported')), |
| 2185 | + ]), |
| 2186 | + fallback: h('div', 'fallback'), |
| 2187 | + }) |
| 2188 | + }, |
| 2189 | + } |
| 2190 | + |
| 2191 | + const root = nodeOps.createElement('div') |
| 2192 | + render(h(Comp), root) |
| 2193 | + expect(serializeInner(root)).toBe(`<div>fallback</div>`) |
| 2194 | + expect(serializeInner(target)).toBe(``) |
| 2195 | + |
| 2196 | + await Promise.all(deps) |
| 2197 | + await nextTick() |
| 2198 | + expect(serializeInner(root)).toBe( |
| 2199 | + `<div><div>async</div><!--teleport start--><!--teleport end--></div>`, |
| 2200 | + ) |
| 2201 | + expect(serializeInner(target)).toBe(`<div>teleported</div>`) |
| 2202 | + }) |
| 2203 | + |
| 2204 | + test('should patch teleport before suspense is resolved', async () => { |
| 2205 | + const target = nodeOps.createElement('div') |
| 2206 | + const text = ref('one') |
| 2207 | + |
| 2208 | + const Async = defineAsyncComponent({ |
| 2209 | + render() { |
| 2210 | + return h('div', 'async') |
| 2211 | + }, |
| 2212 | + }) |
| 2213 | + |
| 2214 | + const Comp = { |
| 2215 | + setup() { |
| 2216 | + return () => |
| 2217 | + h(Suspense, null, { |
| 2218 | + default: h('div', null, [ |
| 2219 | + h(Async), |
| 2220 | + h(Teleport, { to: target }, h('div', text.value)), |
| 2221 | + ]), |
| 2222 | + fallback: h('div', 'fallback'), |
| 2223 | + }) |
| 2224 | + }, |
| 2225 | + } |
| 2226 | + |
| 2227 | + const root = nodeOps.createElement('div') |
| 2228 | + render(h(Comp), root) |
| 2229 | + expect(serializeInner(root)).toBe(`<div>fallback</div>`) |
| 2230 | + expect(serializeInner(target)).toBe(``) |
| 2231 | + |
| 2232 | + text.value = 'two' |
| 2233 | + await nextTick() |
| 2234 | + expect(serializeInner(root)).toBe(`<div>fallback</div>`) |
| 2235 | + expect(serializeInner(target)).toBe(``) |
| 2236 | + |
| 2237 | + await Promise.all(deps) |
| 2238 | + await nextTick() |
| 2239 | + expect(serializeInner(root)).toBe( |
| 2240 | + `<div><div>async</div><!--teleport start--><!--teleport end--></div>`, |
| 2241 | + ) |
| 2242 | + expect(serializeInner(target)).toBe(`<div>two</div>`) |
| 2243 | + }) |
| 2244 | + |
| 2245 | + test('should handle disabled teleport updates before suspense is resolved', async () => { |
| 2246 | + const target = nodeOps.createElement('div') |
| 2247 | + const disabled = ref(false) |
| 2248 | + |
| 2249 | + const Async = defineAsyncComponent({ |
| 2250 | + render() { |
| 2251 | + return h('div', 'async') |
| 2252 | + }, |
| 2253 | + }) |
| 2254 | + |
| 2255 | + const Comp = { |
| 2256 | + setup() { |
| 2257 | + return () => |
| 2258 | + h(Suspense, null, { |
| 2259 | + default: h('div', null, [ |
| 2260 | + h(Async), |
| 2261 | + h( |
| 2262 | + Teleport, |
| 2263 | + { to: target, disabled: disabled.value }, |
| 2264 | + h('div', 'teleported'), |
| 2265 | + ), |
| 2266 | + ]), |
| 2267 | + fallback: h('div', 'fallback'), |
| 2268 | + }) |
| 2269 | + }, |
| 2270 | + } |
| 2271 | + |
| 2272 | + const root = nodeOps.createElement('div') |
| 2273 | + render(h(Comp), root) |
| 2274 | + expect(serializeInner(root)).toBe(`<div>fallback</div>`) |
| 2275 | + expect(serializeInner(target)).toBe(``) |
| 2276 | + |
| 2277 | + disabled.value = true |
| 2278 | + await nextTick() |
| 2279 | + expect(serializeInner(root)).toBe(`<div>fallback</div>`) |
| 2280 | + expect(serializeInner(target)).toBe(``) |
| 2281 | + |
| 2282 | + await Promise.all(deps) |
| 2283 | + await nextTick() |
| 2284 | + expect(serializeInner(root)).toBe( |
| 2285 | + `<div><div>async</div><!--teleport start--><div>teleported</div><!--teleport end--></div>`, |
| 2286 | + ) |
| 2287 | + expect(serializeInner(target)).toBe(``) |
| 2288 | + }) |
| 2289 | + |
2168 | 2290 | //#11617 |
2169 | 2291 | test('update async component before resolve then update again', async () => { |
2170 | 2292 | const arr: boolean[] = [] |
|
0 commit comments