Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add `next/dist/client/components/shared/dynamic` as shared api which server and client components can both support. Dynamic imports will be part of flight on server side. This pr doesn't contain preloading part for client components.
- Loading branch information
Showing
11 changed files
with
66 additions
and
24 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
import React from 'react' | ||
|
||
export type LoaderComponent<P = {}> = Promise<{ | ||
default: React.ComponentType<P> | ||
}> | ||
|
||
export type Loader<P = {}> = () => LoaderComponent<P> | ||
|
||
export type DynamicOptions<P = {}> = { | ||
loader?: Loader<P> | ||
} | ||
|
||
export type LoadableComponent<P = {}> = React.ComponentType<P> | ||
|
||
export default function dynamic<P = {}>( | ||
loader: Loader<P> | ||
): React.ComponentType<P> { | ||
const LazyLoadable = React.lazy(loader) | ||
|
||
return LazyLoadable | ||
} |
7 changes: 7 additions & 0 deletions
7
test/e2e/app-dir/app/app/dashboard/index/dynamic-imports/dynamic.client.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
import dynamic from 'next/dist/client/components/shared/dynamic' | ||
|
||
const Dynamic = dynamic(() => import('../text-dynamic.client')) | ||
|
||
export function NextDynamicClientComponent() { | ||
return <Dynamic /> | ||
} |
7 changes: 7 additions & 0 deletions
7
test/e2e/app-dir/app/app/dashboard/index/dynamic-imports/dynamic.server.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
import dynamic from 'next/dist/client/components/shared/dynamic' | ||
|
||
const Dynamic = dynamic(() => import('../text-dynamic.server')) | ||
|
||
export function NextDynamicServerComponent() { | ||
return <Dynamic /> | ||
} |
4 changes: 2 additions & 2 deletions
4
.../app/dashboard/index/react-lazy.client.js → ...ndex/dynamic-imports/react-lazy.client.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,13 +1,13 @@ | ||
import { useState, lazy } from 'react' | ||
|
||
const Lazy = lazy(() => import('./lazy.client.js')) | ||
const Lazy = lazy(() => import('../text-lazy.client.js')) | ||
|
||
export function LazyClientComponent() { | ||
let [state] = useState('client') | ||
return ( | ||
<> | ||
<Lazy /> | ||
<p className="hi">hello from modern the {state}</p> | ||
<p className="hi">hello from {state}</p> | ||
</> | ||
) | ||
} |
11 changes: 0 additions & 11 deletions
11
test/e2e/app-dir/app/app/dashboard/index/dynamic.client.js
This file was deleted.
Oops, something went wrong.
7 changes: 0 additions & 7 deletions
7
test/e2e/app-dir/app/app/dashboard/index/next-dynamic.client.js
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
11 changes: 11 additions & 0 deletions
11
test/e2e/app-dir/app/app/dashboard/index/text-dynamic.client.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
import { useState } from 'react' | ||
import styles from './dynamic.module.css' | ||
|
||
export default function Dynamic() { | ||
let [state] = useState('dynamic on client') | ||
return ( | ||
<p id="css-text-dynamic-client" className={styles.dynamic}> | ||
{`hello from ${state}`} | ||
</p> | ||
) | ||
} |
9 changes: 9 additions & 0 deletions
9
test/e2e/app-dir/app/app/dashboard/index/text-dynamic.server.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
import styles from './dynamic.module.css' | ||
|
||
export default function Dynamic() { | ||
return ( | ||
<p id="css-text-dynamic-server" className={styles.dynamic}> | ||
hello from dynamic on server | ||
</p> | ||
) | ||
} |
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters