rsnext/test/e2e/app-dir/dynamic
Jiachi Liu d6d6d56133
Remove client only dynamic chunks from edge bundle (#56761)
### Issue

In the client components world, when you're using `next/dynamic` with `ssr: false` to split chunks in pages of edge runtime, you could get the dynamic imported module still bundled in the server bundle for edge runtime. This could easily hit the bundle limit on edge runtime if you're loading a large size of non-SSR module.

This is caused by the whole chunk is still being included when we're creating the client entry. Since the client entry is imported eagerily, webpack will bundle all the modules under it, unless it's explicitly marked not being included.

### Fix

For client components, SSR rendering layer of bundle, non-SSR `next/dynamic` calls, we're transform the result of `dynamic()` call from to conditional import the dynamic loaded module.

From
```js
dynamic(() => import(...))
```
To
```js
dynamic(() => {
  require.resolveWeak(...)
}, { ssr: false })
```

This will only be applied to SSR layer bundle client components non-SSR `next/dynamic` calls and only when webpack is bundling since turbopack doesn't need this. In this way, the server side will be stripped but it can still enter the module graph since we need to traverse if there's SA in client modules with using webpack API `require.resolveWeak`. And for client side bundle will still include the actual module.

Close NEXT-1703
2023-11-16 15:10:28 +00:00
..
app Remove client only dynamic chunks from edge bundle (#56761) 2023-11-16 15:10:28 +00:00
pages/legacy Separate next/dynamic implementation for app and pages (#45565) 2023-02-04 01:45:35 +00:00
ui Fix dynamic no ssr with babel transform (#45091) 2023-01-23 13:39:47 -08:00
dynamic.test.ts Remove client only dynamic chunks from edge bundle (#56761) 2023-11-16 15:10:28 +00:00
next.config.js Remove experimental config from create-next-app (#49241) 2023-05-05 00:22:28 -07:00