Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ensure .client.tsx/.ts/.jsx Client Components can be imported #38591

Merged
merged 2 commits into from Jul 13, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
3 changes: 2 additions & 1 deletion packages/next/build/webpack-config.ts
Expand Up @@ -58,6 +58,7 @@ import { withoutRSCExtensions } from './utils'
import browserslist from 'next/dist/compiled/browserslist'
import loadJsConfig from './load-jsconfig'
import { loadBindings } from './swc'
import { clientComponentRegex } from './webpack/loaders/utils'

const watchOptions = Object.freeze({
aggregateTimeout: 5,
Expand Down Expand Up @@ -1311,7 +1312,7 @@ export default async function getBaseWebpackConfig(
},
},
{
test: /(\.client\.(js|cjs|mjs))$|\/next\/(link|image|future\/image|head|script)/,
test: clientComponentRegex,
issuerLayer: 'sc_server',
use: {
loader: 'next-flight-client-loader',
Expand Down
10 changes: 9 additions & 1 deletion packages/next/build/webpack/loaders/utils.ts
@@ -1,6 +1,14 @@
export const defaultJsFileExtensions = ['js', 'mjs', 'jsx', 'ts', 'tsx']
const imageExtensions = ['jpg', 'jpeg', 'png', 'webp', 'avif']
const nextClientComponents = ['link', 'image', 'head', 'script', 'dynamic']
const nextClientComponents = [
'link',
'image',
// TODO-APP: check if this affects the regex
'future/image',
'head',
'script',
'dynamic',
]

const NEXT_BUILT_IN_CLIENT_RSC_REGEX = new RegExp(
`[\\\\/]next[\\\\/](${nextClientComponents.join('|')})\\.js$`
Expand Down
14 changes: 14 additions & 0 deletions test/e2e/app-dir/app/app/dashboard/client-comp.client.jsx
@@ -0,0 +1,14 @@
import { useEffect, useState } from 'react'

export default function ClientComp() {
const [state, setState] = useState({})
useEffect(() => {
setState({ test: 'HELLOOOO' })
}, [])
return (
<>
<p>Hello</p>
{state.test}
</>
)
}
2 changes: 2 additions & 0 deletions test/e2e/app-dir/app/app/dashboard/page.server.js
@@ -1,8 +1,10 @@
import ClientComp from './client-comp.client'
export default function DashboardPage(props) {
return (
<>
<p className="p">hello from app/dashboard</p>
<p className="green">this is green</p>
<ClientComp />
</>
)
}