context-isolation.test.ts
This file
Path
src/jsx/context-isolation.test.ts
655 lines · 22.1 KiB · TypeScript
Last changed by
chore: update to ts6 in prep for ts7 (#5104)Rahul Mishrabefore adoption3bb9a0e
History of this fileTake it
Merge commit from forkTaku Amanobefore adoptionfab3b13
lines 1–2why, one step back1import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest'2chore: update to ts6 in prep for ts7 (#5104)Rahul Mishrabefore adoption3bb9a0e
lines 3–6why, one step back3const importIndex = () => import('./index')4const importStreaming = () => import('./streaming')5const importHooks = () => import('./hooks')6const importAsyncHooks = () => import('node:async_hooks')fix(jsx): make merged context-isolation tests pass tsc type check (#5037)Yusuke Wadabefore adoptiond4853a8
line 7why, one step back7Merge commit from forkTaku Amanobefore adoptionfab3b13
lines 8–39why, one step back8/**9 * These tests exercise the non-`AsyncLocalStorage` fallback path. They force10 * every `AsyncLocalStorage` acquisition route to fail (and keep it disabled11 * while the module lazily probes for it), then verify the React-style12 * fail-safe: reading context after `await` returns the default value and never13 * another concurrent request's value.14 */15describe('JSX context isolation without AsyncLocalStorage', () => {16 let originalGetBuiltinModule: unknown17 let originalMainModule: unknown18 let warnSpy: ReturnType<typeof vi.spyOn>1920 beforeEach(() => {21 // Disable every route `loadAsyncLocalStorage()` tries. These stay in effect22 // through the first render so the lazy probe caches "unavailable".23 vi.resetModules()24 originalGetBuiltinModule = (process as { getBuiltinModule?: unknown }).getBuiltinModule25 ;(process as { getBuiltinModule?: unknown }).getBuiltinModule = undefined26 originalMainModule = (process as { mainModule?: unknown }).mainModule27 ;(process as { mainModule?: unknown }).mainModule = undefined28 warnSpy = vi.spyOn(console, 'warn').mockImplementation(() => {})29 })3031 afterEach(() => {32 ;(process as { getBuiltinModule?: unknown }).getBuiltinModule = originalGetBuiltinModule33 ;(process as { mainModule?: unknown }).mainModule = originalMainModule34 vi.unstubAllGlobals()35 vi.resetModules()36 warnSpy.mockRestore()37 })3839 it('falls back to the default value after await and never leaks across concurrent renders', async () => {fix(jsx): make merged context-isolation tests pass tsc type check (#5037)Yusuke Wadabefore adoptiond4853a8
line 40why, one step back40 const { createContext, useContext, jsx } = await importIndex()Merge commit from forkTaku Amanobefore adoptionfab3b13
lines 41–106why, one step back4142 const SessionContext = createContext<{ username: string; role: string }>({43 username: 'nobody',44 role: 'none',45 })4647 const waits = new Map<string, Promise<void>>()48 const entered = new Map<string, () => void>()4950 const AdminDashboard = async () => {51 const initialSession = useContext(SessionContext)52 entered.get(initialSession.username)?.()53 await waits.get(initialSession.username)54 const session = useContext(SessionContext)55 if (session.role !== 'admin') {56 return jsx('div', {}, `Access Denied for ${session.username}`)57 }58 return jsx('div', {}, `Welcome Admin ${session.username}. Secret Data: 42`)59 }6061 const render = async (username: string, role: string): Promise<string> =>62 `${await jsx(63 SessionContext.Provider,64 { value: { username, role } },65 jsx(AdminDashboard, {})66 ).toString()}`6768 let resolveAdmin!: () => void69 let resolveAttacker!: () => void70 waits.set(71 'admin',72 new Promise<void>((resolve) => {73 resolveAdmin = resolve74 })75 )76 waits.set(77 'attacker',78 new Promise<void>((resolve) => {79 resolveAttacker = resolve80 })81 )82 const adminEntered = new Promise<void>((resolve) => {83 entered.set('admin', resolve)84 })85 const attackerEntered = new Promise<void>((resolve) => {86 entered.set('attacker', resolve)87 })8889 const adminReq = render('admin', 'admin')90 const attackerReq = render('attacker', 'guest')9192 await Promise.all([adminEntered, attackerEntered])93 resolveAttacker()94 await Promise.resolve()95 resolveAdmin()9697 const [adminHtml, attackerHtml] = await Promise.all([adminReq, attackerReq])9899 // Without AsyncLocalStorage the post-await read sees the default value —100 // the same fail-safe React's request storage degrades to. The critical101 // guarantee is that neither render observes the other request's value.102 expect(adminHtml).toBe('<div>Access Denied for nobody</div>')103 expect(attackerHtml).toBe('<div>Access Denied for nobody</div>')104 })105106 it('warns once when a post-await read falls back to the default value', async () => {fix(jsx): make merged context-isolation tests pass tsc type check (#5037)Yusuke Wadabefore adoptiond4853a8
line 107why, one step back107 const { createContext, useContext, jsx } = await importIndex()Merge commit from forkTaku Amanobefore adoptionfab3b13
lines 108–125why, one step back108109 const ThemeContext = createContext('default')110 const Reader = async () => {111 await new Promise((r) => setTimeout(r, 10))112 return jsx('div', {}, useContext(ThemeContext))113 }114 const render = async () =>115 `${await jsx(ThemeContext.Provider, { value: 'provided' }, jsx(Reader, {})).toString()}`116117 expect(await render()).toBe('<div>default</div>')118 expect(await render()).toBe('<div>default</div>')119120 // Degrading to the default value is reported once, not per read.121 expect(warnSpy).toHaveBeenCalledTimes(1)122 expect(warnSpy.mock.calls[0][0]).toContain('AsyncLocalStorage')123 })124125 it('clears the fallback warning window after an async render rejects', async () => {fix(jsx): make merged context-isolation tests pass tsc type check (#5037)Yusuke Wadabefore adoptiond4853a8
line 126why, one step back126 const { createContext, useContext, jsx } = await importIndex()Merge commit from forkTaku Amanobefore adoptionfab3b13
lines 127–143why, one step back127128 const ThemeContext = createContext('default')129 const Broken = async () => {130 await Promise.resolve()131 throw new Error('boom')132 }133134 await expect(jsx(Broken, {}).toString()).rejects.toThrow('boom')135136 useContext(ThemeContext)137 expect(warnSpy).not.toHaveBeenCalled()138 })139140 it('finds AsyncLocalStorage via process.mainModule.require (Node < 20.16 CJS)', async () => {141 // Re-enable only the legacy route: a CJS entrypoint exposes the main142 // module's `require` even where `process.getBuiltinModule` doesn't exist.143 // Context must then survive `await` with no warning.fix(jsx): make merged context-isolation tests pass tsc type check (#5037)Yusuke Wadabefore adoptiond4853a8
line 144why, one step back144 const { AsyncLocalStorage } = await importAsyncHooks()Merge commit from forkTaku Amanobefore adoptionfab3b13
lines 145–149why, one step back145 ;(process as { mainModule?: unknown }).mainModule = {146 require: (specifier: string) =>147 specifier === 'node:async_hooks' ? { AsyncLocalStorage } : {},148 }149fix(jsx): make merged context-isolation tests pass tsc type check (#5037)Yusuke Wadabefore adoptiond4853a8
line 150why, one step back150 const { createContext, useContext, jsx } = await importIndex()Merge commit from forkTaku Amanobefore adoptionfab3b13
lines 151–164why, one step back151152 const ThemeContext = createContext('default')153 const Reader = async () => {154 await new Promise((r) => setTimeout(r, 10))155 return jsx('div', {}, useContext(ThemeContext))156 }157158 expect(159 `${await jsx(ThemeContext.Provider, { value: 'provided' }, jsx(Reader, {})).toString()}`160 ).toBe('<div>provided</div>')161 expect(warnSpy).not.toHaveBeenCalled()162 })163164 it('keeps a synchronous render synchronous and does not warn', async () => {fix(jsx): make merged context-isolation tests pass tsc type check (#5037)Yusuke Wadabefore adoptiond4853a8
line 165why, one step back165 const { createContext, useContext, jsx } = await importIndex()Merge commit from forkTaku Amanobefore adoptionfab3b13
lines 166–186why, one step back166167 const ThemeContext = createContext('light')168 const Consumer = () => jsx('span', {}, useContext(ThemeContext))169170 const result = jsx(ThemeContext.Provider, { value: 'dark' }, jsx(Consumer, {})).toString()171172 // A purely synchronous render must not be forced async by the serializer.173 expect(result).toBe('<span>dark</span>')174 expect(warnSpy).not.toHaveBeenCalled()175 })176177 const drainStream = async (stream: unknown): Promise<string> => {178 const textDecoder = new TextDecoder()179 let html = ''180 for await (const chunk of stream as AsyncIterable<Uint8Array>) {181 html += textDecoder.decode(chunk)182 }183 return html184 }185186 it('restores provider values for the subtree returned by a resumed async component', async () => {fix(jsx): make merged context-isolation tests pass tsc type check (#5037)Yusuke Wadabefore adoptiond4853a8
line 187why, one step back187 const { createContext, useContext, jsx } = await importIndex()Merge commit from forkTaku Amanobefore adoptionfab3b13
lines 188–205why, one step back188189 const ThemeContext = createContext('default')190 const Inner = () => jsx('span', {}, useContext(ThemeContext))191 const Outer = async () => {192 await new Promise((r) => setTimeout(r, 10))193 // Unlike a useContext() call here in the async body (which degrades to194 // the default), the returned subtree renders with the context values195 // snapshotted at suspension and restored by the renderer.196 return jsx(Inner, {})197 }198199 expect(200 `${await jsx(ThemeContext.Provider, { value: 'provided' }, jsx(Outer, {})).toString()}`201 ).toBe('<span>provided</span>')202 expect(warnSpy).not.toHaveBeenCalled()203 })204205 it('resumes a Suspense-deferred subtree in the captured request store', async () => {fix(jsx): make merged context-isolation tests pass tsc type check (#5037)Yusuke Wadabefore adoptiond4853a8
lines 206–208why, one step back206 const { createContext, useContext, jsx } = await importIndex()207 const { Suspense, renderToReadableStream } = await importStreaming()208 const { use } = await importHooks()Merge commit from forkTaku Amanobefore adoptionfab3b13
lines 209–231why, one step back209210 // A `use()`-suspended child takes the deferred re-render path, which on the211 // fallback path re-establishes the captured render store synchronously.212 const deferred = new Promise<string>((resolve) => setTimeout(() => resolve('done'), 10))213 const ThemeContext = createContext('default')214 const Inner = () => jsx('span', {}, useContext(ThemeContext))215 const Content = () => {216 const value = use(deferred)217 return jsx(ThemeContext.Provider, { value }, jsx(Inner, {}))218 }219220 const html = await drainStream(221 renderToReadableStream(jsx(Suspense, { fallback: jsx('p', {}, 'Loading') }, jsx(Content, {})))222 )223224 expect(html).toContain('Loading')225 expect(html).toContain('<span>done</span>')226 // Providers inside the resumed subtree render in the request store, not in227 // the module-global fallback — so no degradation warning fires.228 expect(warnSpy).not.toHaveBeenCalled()229 })230231 it('resumes a Suspense-deferred subtree with outer provider values', async () => {fix(jsx): make merged context-isolation tests pass tsc type check (#5037)Yusuke Wadabefore adoptiond4853a8
lines 232–234why, one step back232 const { createContext, useContext, jsx } = await importIndex()233 const { Suspense, renderToReadableStream } = await importStreaming()234 const { use } = await importHooks()Merge commit from forkTaku Amanobefore adoptionfab3b13
lines 235–259why, one step back235236 const deferred = new Promise<string>((resolve) => setTimeout(() => resolve('done'), 10))237 const ThemeContext = createContext('default')238 const Content = () => {239 use(deferred)240 return jsx('span', {}, useContext(ThemeContext))241 }242243 const html = await drainStream(244 renderToReadableStream(245 jsx(246 ThemeContext.Provider,247 { value: 'outer' },248 jsx(Suspense, { fallback: jsx('p', {}, 'Loading') }, jsx(Content, {}))249 )250 )251 )252253 expect(html).toContain('Loading')254 expect(html).toContain('<span>outer</span>')255 expect(html).not.toContain('<span>default</span>')256 expect(warnSpy).not.toHaveBeenCalled()257 })258259 it('renders Suspense fallback with outer provider values', async () => {fix(jsx): make merged context-isolation tests pass tsc type check (#5037)Yusuke Wadabefore adoptiond4853a8
lines 260–262why, one step back260 const { createContext, useContext, jsx } = await importIndex()261 const { Suspense, renderToReadableStream } = await importStreaming()262 const { use } = await importHooks()Merge commit from forkTaku Amanobefore adoptionfab3b13
lines 263–288why, one step back263264 const deferred = new Promise<string>((resolve) => setTimeout(() => resolve('done'), 10))265 const ThemeContext = createContext('default')266 const Fallback = () => jsx('p', {}, `Loading ${useContext(ThemeContext)}`)267 const Content = () => {268 const value = use(deferred)269 return jsx('span', {}, value)270 }271272 const html = await drainStream(273 renderToReadableStream(274 jsx(275 ThemeContext.Provider,276 { value: 'outer' },277 jsx(Suspense, { fallback: jsx(Fallback, {}) }, jsx(Content, {}))278 )279 )280 )281282 expect(html).toContain('<p>Loading outer</p>')283 expect(html).toContain('<span>done</span>')284 expect(html).not.toContain('default')285 expect(warnSpy).not.toHaveBeenCalled()286 })287288 it('restores nested provider values in a resumed Suspense subtree', async () => {fix(jsx): make merged context-isolation tests pass tsc type check (#5037)Yusuke Wadabefore adoptiond4853a8
lines 289–291why, one step back289 const { createContext, useContext, jsx, Fragment } = await importIndex()290 const { Suspense, renderToReadableStream } = await importStreaming()291 const { use } = await importHooks()Merge commit from forkTaku Amanobefore adoptionfab3b13
lines 292–322why, one step back292293 const deferred = new Promise<string>((resolve) => setTimeout(() => resolve('done'), 10))294 const ThemeContext = createContext('default')295 const Inner = () => jsx('span', {}, useContext(ThemeContext))296 const OuterSibling = () => jsx('em', {}, useContext(ThemeContext))297 const Content = () => {298 use(deferred)299 return jsx(300 Fragment,301 {},302 jsx(ThemeContext.Provider, { value: 'inner' }, jsx(Inner, {})),303 jsx(OuterSibling, {})304 )305 }306307 const html = await drainStream(308 renderToReadableStream(309 jsx(310 ThemeContext.Provider,311 { value: 'outer' },312 jsx(Suspense, { fallback: jsx('p', {}, 'Loading') }, jsx(Content, {}))313 )314 )315 )316317 expect(html).toContain('<span>inner</span><em>outer</em>')318 expect(html).not.toContain('default')319 expect(warnSpy).not.toHaveBeenCalled()320 })321322 it('keeps sibling Suspense resume contexts isolated when they resolve out of order', async () => {fix(jsx): make merged context-isolation tests pass tsc type check (#5037)Yusuke Wadabefore adoptiond4853a8
lines 323–325why, one step back323 const { createContext, useContext, jsx, Fragment } = await importIndex()324 const { Suspense, renderToReadableStream } = await importStreaming()325 const { use } = await importHooks()Merge commit from forkTaku Amanobefore adoptionfab3b13
lines 326–396why, one step back326327 const ThemeContext = createContext('default')328 const waits = new Map<string, Promise<void>>()329 const entered = new Map<string, () => void>()330 let resolveFirst!: () => void331 let resolveSecond!: () => void332 waits.set(333 'first',334 new Promise<void>((resolve) => {335 resolveFirst = resolve336 })337 )338 waits.set(339 'second',340 new Promise<void>((resolve) => {341 resolveSecond = resolve342 })343 )344 const firstEntered = new Promise<void>((resolve) => {345 entered.set('first', resolve)346 })347 const secondEntered = new Promise<void>((resolve) => {348 entered.set('second', resolve)349 })350 const Content = ({ name }: { name: string }) => {351 entered.get(name)?.()352 use(waits.get(name)!)353 return jsx('span', {}, `${name}:${useContext(ThemeContext)}`)354 }355356 const htmlPromise = drainStream(357 renderToReadableStream(358 jsx(359 Fragment,360 {},361 jsx(362 ThemeContext.Provider,363 { value: 'one' },364 jsx(365 Suspense,366 { fallback: jsx('p', {}, 'Loading one') },367 jsx(Content, { name: 'first' })368 )369 ),370 jsx(371 ThemeContext.Provider,372 { value: 'two' },373 jsx(374 Suspense,375 { fallback: jsx('p', {}, 'Loading two') },376 jsx(Content, { name: 'second' })377 )378 )379 )380 )381 )382383 await Promise.all([firstEntered, secondEntered])384 resolveSecond()385 await Promise.resolve()386 resolveFirst()387388 const html = await htmlPromise389390 expect(html).toContain('<span>first:one</span>')391 expect(html).toContain('<span>second:two</span>')392 expect(html).not.toContain('default')393 expect(warnSpy).not.toHaveBeenCalled()394 })395396 it('resumes ErrorBoundary-deferred children in the captured request store', async () => {fix(jsx): make merged context-isolation tests pass tsc type check (#5037)Yusuke Wadabefore adoptiond4853a8
lines 397–398why, one step back397 const { createContext, useContext, jsx, ErrorBoundary } = await importIndex()398 const { renderToReadableStream } = await importStreaming()Merge commit from forkTaku Amanobefore adoptionfab3b13
lines 399–425why, one step back399400 const deferred = new Promise<string>((resolve) => setTimeout(() => resolve('done'), 10))401 let resolved: string | undefined402 deferred.then((value) => {403 resolved = value404 })405 const ThemeContext = createContext('default')406 const Inner = () => jsx('span', {}, useContext(ThemeContext))407 const Content = () => {408 if (!resolved) {409 // Suspend like use() does so ErrorBoundary defers the re-render.410 throw deferred411 }412 return jsx(ThemeContext.Provider, { value: resolved }, jsx(Inner, {}))413 }414415 const html = await drainStream(416 renderToReadableStream(417 jsx(ErrorBoundary, { fallback: jsx('p', {}, 'Failed') }, jsx(Content, {}))418 )419 )420421 expect(html).toContain('<span>done</span>')422 expect(warnSpy).not.toHaveBeenCalled()423 })424425 it('resumes ErrorBoundary-deferred children with outer provider values', async () => {fix(jsx): make merged context-isolation tests pass tsc type check (#5037)Yusuke Wadabefore adoptiond4853a8
lines 426–427why, one step back426 const { createContext, useContext, jsx, ErrorBoundary } = await importIndex()427 const { renderToReadableStream } = await importStreaming()Merge commit from forkTaku Amanobefore adoptionfab3b13
lines 428–458why, one step back428429 const deferred = new Promise<string>((resolve) => setTimeout(() => resolve('done'), 10))430 let resolved: string | undefined431 deferred.then((value) => {432 resolved = value433 })434 const ThemeContext = createContext('default')435 const Content = () => {436 if (!resolved) {437 // Suspend like use() does so ErrorBoundary defers the re-render.438 throw deferred439 }440 return jsx('span', {}, useContext(ThemeContext))441 }442443 const html = await drainStream(444 renderToReadableStream(445 jsx(446 ThemeContext.Provider,447 { value: 'outer' },448 jsx(ErrorBoundary, { fallback: jsx('p', {}, 'Failed') }, jsx(Content, {}))449 )450 )451 )452453 expect(html).toContain('<span>outer</span>')454 expect(html).not.toContain('<span>default</span>')455 expect(warnSpy).not.toHaveBeenCalled()456 })457458 it('resumes ErrorBoundary fallback rendering with outer provider values', async () => {fix(jsx): make merged context-isolation tests pass tsc type check (#5037)Yusuke Wadabefore adoptiond4853a8
lines 459–460why, one step back459 const { createContext, useContext, jsx, ErrorBoundary } = await importIndex()460 const { renderToReadableStream } = await importStreaming()Merge commit from forkTaku Amanobefore adoptionfab3b13
lines 461–492why, one step back461462 const deferred = new Promise((_resolve, reject) =>463 setTimeout(() => reject(new Error('boom')), 10)464 )465 const ThemeContext = createContext('default')466 const Content = () => {467 throw deferred468 }469470 const html = await drainStream(471 renderToReadableStream(472 jsx(473 ThemeContext.Provider,474 { value: 'outer' },475 jsx(476 ErrorBoundary,477 {478 fallbackRender: (error: Error) =>479 jsx('span', {}, `fallback:${useContext(ThemeContext)}:${error.message}`),480 },481 jsx(Content, {})482 )483 )484 )485 )486487 expect(html).toContain('<span>fallback:outer:boom</span>')488 expect(html).not.toContain('fallback:default')489 expect(warnSpy).not.toHaveBeenCalled()490 })491492 it('resumes ErrorBoundary fallbackRender components with outer provider values', async () => {fix(jsx): make merged context-isolation tests pass tsc type check (#5037)Yusuke Wadabefore adoptiond4853a8
lines 493–494why, one step back493 const { createContext, useContext, jsx, ErrorBoundary } = await importIndex()494 const { renderToReadableStream } = await importStreaming()Merge commit from forkTaku Amanobefore adoptionfab3b13
lines 495–526why, one step back495496 const deferred = new Promise((_resolve, reject) =>497 setTimeout(() => reject(new Error('boom')), 10)498 )499 const ThemeContext = createContext('default')500 const Content = () => {501 throw deferred502 }503 const Fallback = () => jsx('span', {}, `fallback:${useContext(ThemeContext)}`)504505 const html = await drainStream(506 renderToReadableStream(507 jsx(508 ThemeContext.Provider,509 { value: 'outer' },510 jsx(511 ErrorBoundary,512 {513 fallbackRender: () => jsx(Fallback, {}),514 },515 jsx(Content, {})516 )517 )518 )519 )520521 expect(html).toContain('<span>fallback:outer</span>')522 expect(html).not.toContain('fallback:default')523 expect(warnSpy).not.toHaveBeenCalled()524 })525526 it('resumes ErrorBoundary fallback prop rendering with outer provider values', async () => {fix(jsx): make merged context-isolation tests pass tsc type check (#5037)Yusuke Wadabefore adoptiond4853a8
lines 527–528why, one step back527 const { createContext, useContext, jsx, ErrorBoundary } = await importIndex()528 const { renderToReadableStream } = await importStreaming()Merge commit from forkTaku Amanobefore adoptionfab3b13
lines 529–554why, one step back529530 const deferred = new Promise((_resolve, reject) =>531 setTimeout(() => reject(new Error('boom')), 10)532 )533 const ThemeContext = createContext('default')534 const Content = () => {535 throw deferred536 }537 const Fallback = () => jsx('span', {}, `fallback:${useContext(ThemeContext)}`)538539 const html = await drainStream(540 renderToReadableStream(541 jsx(542 ThemeContext.Provider,543 { value: 'outer' },544 jsx(ErrorBoundary, { fallback: jsx(Fallback, {}) }, jsx(Content, {}))545 )546 )547 )548549 expect(html).toContain('<span>fallback:outer</span>')550 expect(html).not.toContain('fallback:default')551 expect(warnSpy).not.toHaveBeenCalled()552 })553554 it('resumes thenable ErrorBoundary fallback prop rendering with outer provider values', async () => {fix(jsx): make merged context-isolation tests pass tsc type check (#5037)Yusuke Wadabefore adoptiond4853a8
lines 555–556why, one step back555 const { createContext, useContext, jsx, ErrorBoundary } = await importIndex()556 const { renderToReadableStream } = await importStreaming()Merge commit from forkTaku Amanobefore adoptionfab3b13
lines 557–587why, one step back557558 const deferred = new Promise((_resolve, reject) =>559 setTimeout(() => reject(new Error('boom')), 10)560 )561 const ThemeContext = createContext('default')562 const Content = () => {563 throw deferred564 }565 const Fallback = () => jsx('span', {}, `fallback:${useContext(ThemeContext)}`)566 const fallback = {567 then(resolve: (value: unknown) => void) {568 setTimeout(() => resolve(jsx(Fallback, {})), 0)569 },570 }571572 const html = await drainStream(573 renderToReadableStream(574 jsx(575 ThemeContext.Provider,576 { value: 'outer' },577 jsx(ErrorBoundary, { fallback }, jsx(Content, {}))578 )579 )580 )581582 expect(html).toContain('<span>fallback:outer</span>')583 expect(html).not.toContain('fallback:default')584 expect(warnSpy).not.toHaveBeenCalled()585 })586587 it('resumes synchronous ErrorBoundary fallback rendering with outer provider values', async () => {fix(jsx): make merged context-isolation tests pass tsc type check (#5037)Yusuke Wadabefore adoptiond4853a8
line 588why, one step back588 const { createContext, useContext, jsx, ErrorBoundary } = await importIndex()Merge commit from forkTaku Amanobefore adoptionfab3b13
lines 589–612why, one step back589590 const ThemeContext = createContext('default')591 const Content = () => {592 throw new Error('boom')593 }594595 expect(596 `${await jsx(597 ThemeContext.Provider,598 { value: 'outer' },599 jsx(600 ErrorBoundary,601 {602 fallbackRender: (error: Error) =>603 jsx('span', {}, `fallback:${useContext(ThemeContext)}:${error.message}`),604 },605 jsx(Content, {})606 )607 ).toString()}`608 ).toBe('<span>fallback:outer:boom</span>')609 expect(warnSpy).not.toHaveBeenCalled()610 })611612 it('resumes synchronous ErrorBoundary fallbackRender components with outer provider values', async () => {fix(jsx): make merged context-isolation tests pass tsc type check (#5037)Yusuke Wadabefore adoptiond4853a8
line 613why, one step back613 const { createContext, useContext, jsx, ErrorBoundary } = await importIndex()Merge commit from forkTaku Amanobefore adoptionfab3b13
lines 614–637why, one step back614615 const ThemeContext = createContext('default')616 const Content = () => {617 throw new Error('boom')618 }619 const Fallback = () => jsx('span', {}, `fallback:${useContext(ThemeContext)}`)620621 expect(622 `${await jsx(623 ThemeContext.Provider,624 { value: 'outer' },625 jsx(626 ErrorBoundary,627 {628 fallbackRender: () => jsx(Fallback, {}),629 },630 jsx(Content, {})631 )632 ).toString()}`633 ).toBe('<span>fallback:outer</span>')634 expect(warnSpy).not.toHaveBeenCalled()635 })636637 it('resumes synchronous ErrorBoundary fallback prop rendering with outer provider values', async () => {fix(jsx): make merged context-isolation tests pass tsc type check (#5037)Yusuke Wadabefore adoptiond4853a8
line 638why, one step back638 const { createContext, useContext, jsx, ErrorBoundary } = await importIndex()Merge commit from forkTaku Amanobefore adoptionfab3b13
lines 639–655why, one step back639640 const ThemeContext = createContext('default')641 const Content = () => {642 throw new Error('boom')643 }644 const Fallback = () => jsx('span', {}, `fallback:${useContext(ThemeContext)}`)645646 expect(647 `${await jsx(648 ThemeContext.Provider,649 { value: 'outer' },650 jsx(ErrorBoundary, { fallback: jsx(Fallback, {}) }, jsx(Content, {}))651 ).toString()}`652 ).toBe('<span>fallback:outer</span>')653 expect(warnSpy).not.toHaveBeenCalled()654 })655})