Files
Jiachi LiuandGitHub a035224dc3 Pick esm main fields and condition names first for RSC server layer (#50548)
For RSC server layer so far we bundle all dependencies, ESM format is the better one rather than CJS to analyze and tree-shake out the unused parts. This PR changes pick the condition names that are in ESM format first for server layer.

Also fixes the misorder of condition names of edge runtime, `conditionNames` should only contain either ESM or CJS, previously the main fields are mixed with conditon names which is not expected for webpack, we separate them now.

Since we're picking ESM instead CJS now, the error of require `exports * from` doesn't exist anymore, but if you're using a CJS dependency which require a ESM package, it will error. This is the existing behavior for our webpack configuration but could happen on server layer bundling

Other related changes:

* Imports are hoisted in ESM, so migrate`enhanceGlobals` to a imported module
* Use `...` to pick the proper imports by import expression, and prefer the `react-server` / `edge-light` condition names for corresponding cases
* Remove edge SSR duplicated `middleware` export checking
2023-06-08 16:24:03 +00:00

20 lines
455 B
JavaScript

import Nav from '../components/nav'
import { headers } from 'next/headers'
const envVar = process.env.ENV_VAR_TEST
const headerKey = 'x-next-test-client'
export default function Index() {
const headersList = headers()
const header = headersList.get(headerKey)
return (
<div>
<h1>{`component:index.server`}</h1>
<div id="env">{'env:' + envVar}</div>
<div id="header">{'header:' + header}</div>
<Nav />
</div>
)
}