Unverified Commit 56d0988a authored by Jiachi Liu's avatar Jiachi Liu Committed by GitHub

Fix: css in next/dynamic component in edge runtime (#64382)

### What

Wrap async local storage for all edge runtime routes in adapter 

Basically fixed the case reported in [this
tweet](https://x.com/keegandonley/status/1778538456458854880)

### Why

We're relying on the ALS for dynamic css preloading but we didn't wrap
the ALS for request handlers for edge. So if you have CSS imports in
`next/dynamic` in edge runtime it would break.

Closes NEXT-3085
parent 0b3ead5e
...@@ -244,7 +244,13 @@ export async function adapter( ...@@ -244,7 +244,13 @@ export async function adapter(
) )
) )
} }
return params.handler(request, event) return RequestAsyncStorageWrapper.wrap(
requestAsyncStorage,
{
req: request,
},
() => params.handler(request, event)
)
}) })
// check if response is a Response object // check if response is a Response object
......
...@@ -5,10 +5,10 @@ export function PreloadCss({ moduleIds }: { moduleIds: string[] | undefined }) { ...@@ -5,10 +5,10 @@ export function PreloadCss({ moduleIds }: { moduleIds: string[] | undefined }) {
if (typeof window !== 'undefined') { if (typeof window !== 'undefined') {
return null return null
} }
const { const getExpectedRequestStore: typeof import('../../../client/components/request-async-storage.external').getExpectedRequestStore =
getExpectedRequestStore, require('../../../client/components/request-async-storage.external').getExpectedRequestStore
} = require('../../../client/components/request-async-storage.external')
const requestStore = getExpectedRequestStore() const requestStore = getExpectedRequestStore('next/dynamic css')
const allFiles = [] const allFiles = []
......
export { default } from '../page'
export const runtime = 'edge'
...@@ -31,6 +31,23 @@ createNextDescribe( ...@@ -31,6 +31,23 @@ createNextDescribe(
}) })
}) })
it('should only apply corresponding css for page loaded in edge runtime', async () => {
const browser = await next.browser('/ssr/edge')
await retry(async () => {
expect(
await browser.eval(
`window.getComputedStyle(document.querySelector('.text')).color`
)
).toBe('rgb(255, 0, 0)')
// Default border width, which is not effected by bar.css that is not loaded in /ssr
expect(
await browser.eval(
`window.getComputedStyle(document.querySelector('.text')).borderWidth`
)
).toBe('0px')
})
})
it('should only apply corresponding css for page loaded that /another', async () => { it('should only apply corresponding css for page loaded that /another', async () => {
const browser = await next.browser('/another') const browser = await next.browser('/another')
await retry(async () => { await retry(async () => {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment