Skip to content

Commit

Permalink
Alias next/dynamic to lazy impl for appDir
Browse files Browse the repository at this point in the history
shorter path
  • Loading branch information
huozhi committed Oct 6, 2022
1 parent 21605a5 commit f60ae22
Show file tree
Hide file tree
Showing 5 changed files with 19 additions and 8 deletions.
17 changes: 16 additions & 1 deletion packages/next/build/webpack-config.ts
Expand Up @@ -1586,13 +1586,28 @@ export default async function getBaseWebpackConfig(
} as any,
]
: []),
// Alias `next/dynamic` to React.lazy implementation for RSC
...(hasServerComponents
? [
{
test: codeCondition.test,
include: [appDir],
resolve: {
alias: {
[require.resolve('next/dynamic')]:
'next/dist/client/components/dynamic',
},
},
},
]
: []),
...(hasServerComponents && (isNodeServer || isEdgeServer)
? [
// RSC server compilation loaders
{
test: codeCondition.test,
include: [
dir,
appDir,
// To let the internal client components passing through flight loader
/next[\\/]dist/,
],
Expand Down
Expand Up @@ -15,7 +15,5 @@ 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
return React.lazy(loader)
}
2 changes: 0 additions & 2 deletions packages/next/shared/lib/dynamic.tsx
@@ -1,5 +1,3 @@
'client'

import React from 'react'
import Loadable from './loadable'

Expand Down
@@ -1,6 +1,6 @@
'client'

import dynamic from 'next/dist/client/components/shared/dynamic'
import dynamic from 'next/dynamic'

const Dynamic = dynamic(() => import('../text-dynamic-client'))

Expand Down
@@ -1,4 +1,4 @@
import dynamic from 'next/dist/client/components/shared/dynamic'
import dynamic from 'next/dynamic'

const Dynamic = dynamic(() => import('../text-dynamic-server'))

Expand Down

0 comments on commit f60ae22

Please sign in to comment.