Skip to content

Commit 3f8f72b

Browse files
authored
Remove internal client next api detection (#40646)
Follow up for #40415 Remove internal next client api determination, fully relying on `'client'` directive. Change `.client.js` extension to `.js ` in tests, remove legacy / unused test files
1 parent 295f9da commit 3f8f72b

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

53 files changed

+24
-263
lines changed

packages/next/build/webpack-config.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1483,7 +1483,7 @@ export default async function getBaseWebpackConfig(
14831483
include: [
14841484
dir,
14851485
// To let the internal client components passing through flight loader
1486-
/next[\\/]dist[\\/]client[\\/]/,
1486+
/next[\\/]dist/,
14871487
],
14881488
issuerLayer: WEBPACK_LAYERS.server,
14891489
use: {

packages/next/build/webpack/loaders/next-flight-loader/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,6 @@ export default async function transformSource(
4444
})
4545

4646
const rscType = getRSCModuleType(source)
47-
const isModule = swcAST.type === 'Module'
4847
const createError = (name: string) =>
4948
new Error(
5049
`${name} is not supported in client components.\nFrom: ${this.resourcePath}`
@@ -74,6 +73,7 @@ export default async function transformSource(
7473
return callback(null, source, sourceMap)
7574
}
7675

76+
const isModule = swcAST.type === 'Module'
7777
const code = transformServer(source, isModule)
7878
return callback(null, code, sourceMap)
7979
}
Lines changed: 1 addition & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,34 +1,12 @@
11
import { RSC_MODULE_TYPES } from '../../../shared/lib/constants'
22

3-
const nextClientComponents = [
4-
'dist/client/link',
5-
'dist/client/image',
6-
'dist/client/future/image',
7-
'dist/shared/lib/head',
8-
'dist/client/script',
9-
'dist/shared/lib/dynamic',
10-
]
11-
123
const imageExtensions = ['jpg', 'jpeg', 'png', 'webp', 'avif']
134
const imageRegex = new RegExp(`\\.(${imageExtensions.join('|')})$`)
145

15-
const NEXT_API_CLIENT_RSC_REGEX = new RegExp(
16-
`next[\\\\/](${nextClientComponents.join('|')})(\\.js)?`
17-
)
18-
19-
// Cover resource paths like `next/dist/client/*`
20-
export function isNextBuiltInClientComponent(resource: string) {
21-
return NEXT_API_CLIENT_RSC_REGEX.test(resource)
22-
}
23-
246
export function isClientComponentModule(mod: {
257
resource: string
268
buildInfo: any
279
}) {
2810
const hasClientDirective = mod.buildInfo.rsc?.type === RSC_MODULE_TYPES.client
29-
return (
30-
isNextBuiltInClientComponent(mod.resource) ||
31-
hasClientDirective ||
32-
imageRegex.test(mod.resource)
33-
)
11+
return hasClientDirective || imageRegex.test(mod.resource)
3412
}

test/e2e/app-dir/rsc-basic.test.ts

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -150,17 +150,6 @@ describe('app dir - react server components', () => {
150150
expect(sharedServerModule[0][1]).toBe(sharedServerModule[1][1])
151151
expect(sharedClientModule[0][1]).toBe(sharedClientModule[1][1])
152152
expect(sharedServerModule[0][1]).not.toBe(sharedClientModule[0][1])
153-
154-
// Note: This is currently unsupported because packages from another layer
155-
// will not be re-initialized by webpack.
156-
// Should import 2 module instances for node_modules too.
157-
// const modFromClient = main.match(
158-
// /node_modules instance from \.client\.js:(\d+)/
159-
// )
160-
// const modFromServer = main.match(
161-
// /node_modules instance from \.server\.js:(\d+)/
162-
// )
163-
// expect(modFromClient[1]).not.toBe(modFromServer[1])
164153
})
165154

166155
it('should be able to navigate between rsc routes', async () => {

test/e2e/app-dir/rsc-basic/app/css-in-js/page.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
import Comp from './styled-jsx.client'
2-
import StyledComp from './styled-components.client'
1+
import Comp from './styled-jsx'
2+
import StyledComp from './styled-components'
33

44
export default function Page() {
55
return (

test/e2e/app-dir/rsc-basic/app/css-modules/page.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
// CSS modules can only be imported inside client components for now.
2-
import RedText from '../../components/red/index.client'
2+
import RedText from '../../components/red/index'
33

44
export default function CSSM() {
55
return (

test/e2e/app-dir/rsc-basic/app/layout.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import React from 'react'
2-
import RootStyleRegistry from './root-style-registry.client'
2+
import RootStyleRegistry from './root-style-registry'
33

44
export default function AppLayout({ children }) {
55
return (

test/e2e/app-dir/rsc-basic/app/native-module/page.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import fs from 'fs'
22

3-
import Foo from '../../components/foo.client'
3+
import Foo from '../../components/foo'
44

55
export default function Page() {
66
return (

test/e2e/app-dir/rsc-basic/app/partial-hydration/page.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { Suspense } from 'react'
22

3-
import Counter from '../../components/partial-hydration-counter.client'
3+
import Counter from '../../components/partial-hydration-counter'
44

55
let result
66
let promise

test/e2e/app-dir/rsc-basic/app/routes/[dynamic]/page.js.bak

Lines changed: 0 additions & 21 deletions
This file was deleted.

test/e2e/app-dir/rsc-basic/app/shared/page.js

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,9 @@
1-
import ClientFromDirect from '../../components/client.client'
1+
import ClientFromDirect from '../../components/client'
22
import ClientFromShared from '../../components/shared'
3-
import SharedFromClient from '../../components/shared.client'
4-
import Random from '../../components/random-module-instance.client'
3+
import SharedFromClient from '../../components/shared-client'
4+
import Random from '../../components/random-module-instance'
55
import Bar from '../../components/bar'
66

7-
// import { random } from 'random-module-instance'
8-
97
export default function Page() {
108
// All three client components should be rendered correctly, but only
119
// shared component is a server component, and another is a client component.
@@ -16,7 +14,6 @@ export default function Page() {
1614
<div id="main" suppressHydrationWarning>
1715
<Random />
1816
<br />
19-
{/* {`node_modules instance from .server.js:` + random} */}
2017
<br />
2118
<ClientFromDirect />
2219
<br />

test/e2e/app-dir/rsc-basic/app/various-exports/page.js

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,13 @@ import { a, b, c, d, e } from '../../components/shared-exports'
33
// client default, named exports
44
import DefaultArrow, {
55
Named as ClientNamed,
6-
} from '../../components/client-exports.client'
6+
} from '../../components/client-exports'
77

8-
import { Cjs as CjsShared } from '../../components/cjs'
9-
import { Cjs as CjsClient } from '../../components/cjs.client'
8+
import { Cjs as CjsShared } from '../../components/cjs-server'
9+
import { Cjs as CjsClient } from '../../components/cjs-client'
1010

11-
import { One, Two, TwoAliased } from '../../components/export-all/index.client'
11+
// client exports all
12+
import { One, Two, TwoAliased } from '../../components/export-all'
1213

1314
export default function Page() {
1415
return (

test/e2e/app-dir/rsc-basic/components/bar.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import Foo from './foo.client'
1+
import Foo from './foo'
22

33
export default function Bar() {
44
return (

test/e2e/app-dir/rsc-basic/components/random-module-instance.client.js renamed to test/e2e/app-dir/rsc-basic/components/random-module-instance.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,5 +3,5 @@
33
import { random } from 'random-module-instance'
44

55
export default function () {
6-
return `node_modules instance from .client.js:${random}`
6+
return `node_modules instance from client module ${random}`
77
}

test/e2e/app-dir/rsc-basic/components/router-path.client.js

Lines changed: 0 additions & 8 deletions
This file was deleted.

test/e2e/app-dir/rsc-basic/components/shared.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import React from 'react'
2-
import Client from './client.client'
2+
import Client from './client'
33

44
const random = ~~(Math.random() * 10000)
55

Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
export default function bar() {
2-
return 'bar.client'
2+
return 'bar'
33
}

test/integration/react-streaming/app/components/bar.server.js

Lines changed: 0 additions & 9 deletions
This file was deleted.

test/integration/react-streaming/app/components/cjs.client.js

Lines changed: 0 additions & 3 deletions
This file was deleted.

test/integration/react-streaming/app/components/cjs.js

Lines changed: 0 additions & 3 deletions
This file was deleted.

test/integration/react-streaming/app/components/client-exports.client.js

Lines changed: 0 additions & 5 deletions
This file was deleted.

test/integration/react-streaming/app/components/client.client.js

Lines changed: 0 additions & 7 deletions
This file was deleted.

test/integration/react-streaming/app/components/container.server.js

Lines changed: 0 additions & 3 deletions
This file was deleted.

test/integration/react-streaming/app/components/export-all/index.client.js

Lines changed: 0 additions & 1 deletion
This file was deleted.

test/integration/react-streaming/app/components/export-all/one.js

Lines changed: 0 additions & 6 deletions
This file was deleted.

test/integration/react-streaming/app/components/export-all/two.js

Lines changed: 0 additions & 3 deletions
This file was deleted.
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
export default function foo() {
2-
return 'foo.client'
2+
return 'foo'
33
}
44

55
export const config = 'this is not page config'

test/integration/react-streaming/app/components/nav.js

Lines changed: 0 additions & 23 deletions
This file was deleted.

test/integration/react-streaming/app/components/partial-hydration-counter.client.js

Lines changed: 0 additions & 20 deletions
This file was deleted.

test/integration/react-streaming/app/components/random-module-instance.client.js

Lines changed: 0 additions & 5 deletions
This file was deleted.

test/integration/react-streaming/app/components/red/index.client.js

Lines changed: 0 additions & 5 deletions
This file was deleted.

test/integration/react-streaming/app/components/red/style.module.css

Lines changed: 0 additions & 3 deletions
This file was deleted.

test/integration/react-streaming/app/components/router-path.client.js

Lines changed: 0 additions & 6 deletions
This file was deleted.

test/integration/react-streaming/app/components/shared-exports.js

Lines changed: 0 additions & 10 deletions
This file was deleted.

test/integration/react-streaming/app/components/shared.client.js

Lines changed: 0 additions & 3 deletions
This file was deleted.

test/integration/react-streaming/app/components/shared.js

Lines changed: 0 additions & 21 deletions
This file was deleted.

test/integration/react-streaming/app/components/styled-jsx.client.js

Lines changed: 0 additions & 12 deletions
This file was deleted.

test/integration/react-streaming/app/pages/dynamic-imports.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
import { lazy, Suspense } from 'react'
22
import dynamic from 'next/dynamic'
33

4-
const Foo = lazy(() => import('../components/foo.client'))
5-
const Bar = dynamic(() => import('../components/bar.client'), {
4+
const Foo = lazy(() => import('../components/foo'))
5+
const Bar = dynamic(() => import('../components/bar'), {
66
suspense: true,
77
})
88

0 commit comments

Comments
 (0)