rsnext/packages/next/client
Jiachi Liu cd0ebd8e8c
Implement loadable with lazy and suspense for next dynamic (#42589)
### Summary

Migrate `next/dynamic` to implementation based on `React.lazy` and
`Suspense`. Then it becomes easier to migrate the existing code in pages
to layouts. Then we can support both `ssr` and `loading` option for
`next/dynamic`.

For `loading` option, it will work like `Suspense`'s `fallback` property

```js
<Suspense fallback={loading}>
  <DynamicComponent />
 </Suspense>
```

For `ssr` option, by default `React.lazy` supports SSR, but we'll
disable the `ssr: false` case for dynamic import in server components
since there's no client side involved.

Then we don't need `suspense` option anymore as react >= 18 is always
required. Mark it as deprecated.

It also supports to load client component dynamically in server
components now.

#### Code code changes
* switch loadable component to `lazy` + `Suspense`
* will make sure it's retuning a module from `loader()` to
`loader().then(mod => ({ default: mod.default || mod }))` since `lazy()`
only accepts loader returning a module
* Inside suspense boundary, throwing an error for ssr: false, catch the
error on server and client side and ignore it.
* Ignore options like ssr: false for server components since they're on
server, doesn't make sense
* Remove legacy dynamic related transform
#### Feature changes
* `next/dynamic` will work in the same way across the board (appDir and
pages)
* For the throwing error, will make it become a API that throws error
later in the future, so users can customize more with `Suspense`
* You can load client components now in server components with dynamic.
Resolves #43147

#### Tests
* existing dynamic tests all work
* add case: import client component and load through next/dynamic in
server components

### Issues
2022-12-07 19:42:10 +01:00
..
compat next/compat/router (#42502) 2022-11-07 18:16:28 +00:00
components Implement loadable with lazy and suspense for next dynamic (#42589) 2022-12-07 19:42:10 +01:00
dev Remove stack trace from full reload warning (#43453) 2022-11-28 13:18:26 +00:00
legacy Replace global with globalThis (#42627) 2022-11-08 14:45:30 +01:00
portal refactor(portal): remove useRef from portal component (#39792) 2022-08-21 09:39:43 +00:00
add-base-path.ts Extract router utils to common functions (#37313) 2022-05-30 20:19:37 +02:00
add-locale.ts Extract router utils to common functions (#37313) 2022-05-30 20:19:37 +02:00
app-bootstrap.js Load beforeInteractive scripts properly without blocking hydration (#41164) 2022-10-09 15:08:51 +00:00
app-index.tsx Implement loadable with lazy and suspense for next dynamic (#42589) 2022-12-07 19:42:10 +01:00
app-next-dev.js Load beforeInteractive scripts properly without blocking hydration (#41164) 2022-10-09 15:08:51 +00:00
app-next.js Merge app internal chunk into main chunk for layouts (#41902) 2022-10-27 16:50:46 -07:00
detect-domain-locale.ts Extract router utils to common functions (#37313) 2022-05-30 20:19:37 +02:00
get-domain-locale.ts Extract router utils to common functions (#37313) 2022-05-30 20:19:37 +02:00
has-base-path.ts Extract router utils to common functions (#37313) 2022-05-30 20:19:37 +02:00
head-manager.ts Migrate head side effects to hooks (#37526) 2022-06-08 11:26:57 +00:00
image.tsx Remove useState from next/image (#43587) 2022-11-30 18:30:02 -08:00
index.tsx Implement loadable with lazy and suspense for next dynamic (#42589) 2022-12-07 19:42:10 +01:00
link.tsx perf: disable prefetching for links in viewport in development for app routes (#43730) 2022-12-05 13:49:37 +00:00
next-dev.js Add hard navigation guard and fix middleware rewrite cases (#37815) 2022-06-20 11:31:19 +00:00
next.js Split up & tweak next/client initialization (#33838) 2022-03-07 17:09:55 +00:00
normalize-locale-path.ts Extract router utils to common functions (#37313) 2022-05-30 20:19:37 +02:00
normalize-trailing-slash.ts Update experimental skipTrailingSlashRedirect handling (#43201) 2022-11-21 13:25:01 -08:00
page-loader.ts feat(next): Support has match and locale option on middleware config (#39257) 2022-08-31 11:23:30 -05:00
performance-relayer-app.ts Optimize bundle size for appDir (#42252) 2022-10-31 17:50:35 +00:00
performance-relayer.ts add attribution to web vitals (#39368) 2022-10-04 00:17:30 +00:00
remove-base-path.ts Extract router utils to common functions (#37313) 2022-05-30 20:19:37 +02:00
remove-locale.ts Extract router utils to common functions (#37313) 2022-05-30 20:19:37 +02:00
request-idle-callback.ts types: better type definition for internal utils (#43070) 2022-11-19 16:09:13 -08:00
route-announcer.tsx next/compat/router (#42502) 2022-11-07 18:16:28 +00:00
route-loader.ts Adopt script rejection pattern for link onerror. (#42645) 2022-11-09 19:58:20 +00:00
router.ts next/compat/router (#42502) 2022-11-07 18:16:28 +00:00
script.tsx Bundle ssr client layer excepts react externals (#41606) 2022-10-22 16:33:51 -07:00
trusted-types.ts Route Loader Trusted Types Violation Fix (#34730) 2022-05-03 23:22:08 +00:00
use-intersection.tsx refactor(use-intersection): remove useRef usage (#39791) 2022-08-21 10:10:09 +00:00
with-router.tsx Upgrade typescript to 4.8.2 (#39979) 2022-08-29 16:56:02 +00:00