Unverified Commit 21255395 authored by Tim Neutkens's avatar Tim Neutkens Committed by GitHub

Fix issue with ComponentMod being read in Turbopack (#62141)

## What?

Fixes an issue where trying to build an edge runtime page with
generateStaticParams fails to read `ComponentMod`. Discussed with @sokra
and found that changing it to `import()` resolves the problem.

<!-- Thanks for opening a PR! Your contribution is much appreciated.
To make sure your PR is handled as smoothly as possible we request that
you follow the checklist sections below.
Choose the right checklist for the change(s) that you're making:

## For Contributors

### Improving Documentation

- Run `pnpm prettier-fix` to fix formatting issues before opening the
PR.
- Read the Docs Contribution Guide to ensure your contribution follows
the docs guidelines:
https://nextjs.org/docs/community/contribution-guide

### Adding or Updating Examples

- The "examples guidelines" are followed from our contributing doc
https://github.com/vercel/next.js/blob/canary/contributing/examples/adding-examples.md
- Make sure the linting passes by running `pnpm build && pnpm lint`. See
https://github.com/vercel/next.js/blob/canary/contributing/repository/linting.md

### Fixing a bug

- Related issues linked using `fixes #number`
- Tests added. See:
https://github.com/vercel/next.js/blob/canary/contributing/core/testing.md#writing-tests-for-nextjs
- Errors have a helpful link attached, see
https://github.com/vercel/next.js/blob/canary/contributing.md

### Adding a feature

- Implements an existing feature request or RFC. Make sure the feature
request has been accepted for implementation before opening a PR. (A
discussion must be opened, see
https://github.com/vercel/next.js/discussions/new?category=ideas)
- Related issues/discussions are linked using `fixes #number`
- e2e tests added
(https://github.com/vercel/next.js/blob/canary/contributing/core/testing.md#writing-tests-for-nextjs)
- Documentation added
- Telemetry added. In case of a feature if it's used or not.
- Errors have a helpful link attached, see
https://github.com/vercel/next.js/blob/canary/contributing.md


## For Maintainers

- Minimal description (aim for explaining to someone not on the team to
understand the PR)
- When linking to a Slack thread, you might want to share details of the
conclusion
- Link both the Linear (Fixes NEXT-xxx) and the GitHub issues
- Add review comments if necessary to explain to the reviewer the logic
behind a change

### What?

### Why?

### How?

Closes NEXT-
Fixes #

-->


Closes NEXT-2514
parent 96599a1b
......@@ -24,11 +24,7 @@ pub async fn wrap_edge_entry(
let source = formatdoc!(
r#"
self._ENTRIES ||= {{}}
self._ENTRIES[{}] = new Proxy(Promise.resolve(require('MODULE')), {{
get(modProm, name) {{
return (...args) => modProm.then(mod => (0, mod[name])(...args))
}}
}})
self._ENTRIES[{}] = import('MODULE')
"#,
StringifyJs(&format_args!("middleware_{}", pathname))
);
......
......@@ -1552,8 +1552,9 @@ export async function isPageStatic({
useCache: true,
distDir,
})
const mod =
runtime.context._ENTRIES[`middleware_${edgeInfo.name}`].ComponentMod
const mod = (
await runtime.context._ENTRIES[`middleware_${edgeInfo.name}`]
).ComponentMod
isClientComponent = isClientReference(mod)
componentsResult = {
......
declare const _ENTRIES: any
async function registerInstrumentation() {
if (
const register =
'_ENTRIES' in globalThis &&
_ENTRIES.middleware_instrumentation &&
_ENTRIES.middleware_instrumentation.register
) {
(await _ENTRIES.middleware_instrumentation).register
if (register) {
try {
await _ENTRIES.middleware_instrumentation.register()
await register()
} catch (err: any) {
err.message = `An error occurred while loading instrumentation hook: ${err.message}`
throw err
......
......@@ -102,8 +102,9 @@ export const run = withTaggedErrors(async function runWithTaggedErrors(params) {
const edgeFunction: (args: {
request: RequestData
}) => Promise<FetchEventResult> =
runtime.context._ENTRIES[`middleware_${params.name}`].default
}) => Promise<FetchEventResult> = (
await runtime.context._ENTRIES[`middleware_${params.name}`]
).default
const cloned = !['HEAD', 'GET'].includes(params.request.method)
? params.request.body?.cloneBodyStream()
......
......@@ -538,6 +538,8 @@ createNextDescribe(
"dynamic-no-gen-params-ssr/[slug]/page_client-reference-manifest.js",
"dynamic-no-gen-params/[slug]/page.js",
"dynamic-no-gen-params/[slug]/page_client-reference-manifest.js",
"dynamic-param-edge/[slug]/page.js",
"dynamic-param-edge/[slug]/page_client-reference-manifest.js",
"fetch-no-cache/page.js",
"fetch-no-cache/page_client-reference-manifest.js",
"flight/[slug]/[slug2]/page.js",
......@@ -3125,5 +3127,10 @@ createNextDescribe(
})
}
})
it('should build dynamic param with edge runtime correctly', async () => {
const browser = await next.browser('/dynamic-param-edge/hello')
expect(await browser.elementByCss('#slug').text()).toBe('hello')
})
}
)
export default function Hello({ params }) {
return <h1 id="slug">{params.slug}</h1>
}
export function generateStaticParams() {
return [
{
params: {
slug: 'hello',
},
},
]
}
export const runtime = 'edge'
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