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

feat!: support latest Next.js versions #7026

Merged
merged 5 commits into from
Jul 8, 2024
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@
"lint-staged": "^14.0.1",
"minimist": "1.2.8",
"mongodb-memory-server": "^9.0",
"next": "15.0.0-rc.0",
"next": "15.0.0-canary.53",
"open": "^10.1.0",
"p-limit": "^5.0.0",
"pino": "8.15.0",
Expand Down
2 changes: 1 addition & 1 deletion packages/next/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@
},
"peerDependencies": {
"graphql": "^16.8.1",
"next": "^15.0.0-rc.0",
"next": "^15.0.0-canary.53",
"payload": "workspace:*"
},
"engines": {
Expand Down
10 changes: 2 additions & 8 deletions packages/next/src/views/Document/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -196,13 +196,6 @@ export const Document: React.FC<AdminViewProps> = async ({
}
}

const viewComponentProps: ServerSideEditViewProps = {
initPageResult,
params,
routeSegments: segments,
searchParams,
}

return (
<DocumentInfoProvider
action={action}
Expand Down Expand Up @@ -246,13 +239,14 @@ export const Document: React.FC<AdminViewProps> = async ({
<RenderCustomComponent
CustomComponent={ViewOverride || CustomView}
DefaultComponent={DefaultView}
componentProps={viewComponentProps}
serverOnlyProps={{
i18n,
initPageResult,
locale,
params,
payload,
permissions,
routeSegments: segments,
searchParams,
user,
}}
Expand Down
42 changes: 13 additions & 29 deletions packages/payload/src/utilities/isReactComponent.ts
Original file line number Diff line number Diff line change
@@ -1,47 +1,31 @@
import type React from 'react'

import { isPlainObject } from './isPlainObject.js'

/*
For reference: console.log output of [ClientComponent, RSC] array, tested in Turbo and Webpack (14.3.0-canary.37)

Both component functions async:

Turbo: [ [Function (anonymous)], [AsyncFunction: ExampleServer] ]
Webpack: [ {}, [AsyncFunction: ExampleServer] ]


Both component functions non-async:

Turbo: [ [Function (anonymous)], [Function: ExampleServer] ]
Webpack: [ {}, [Function: ExampleServer] ]

*/
const clientRefSymbol = Symbol.for('react.client.reference')
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is soo nice


export function isReactServerComponentOrFunction<T extends any>(
component: React.ComponentType | any,
): component is T {
const isClassComponent =
typeof component === 'function' &&
component.prototype &&
typeof component.prototype.render === 'function'

const isFunctionalComponent =
typeof component === 'function' && (!component.prototype || !component.prototype.render)
if (component === null || component === undefined) {
return false
}
const hasClientComponentSymbol = component.$$typeof == clientRefSymbol
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Amazing


const isFunctionalComponent = typeof component === 'function'
// Anonymous functions are Client Components in Turbopack. RSCs should have a name
const isAnonymousFunction = typeof component === 'function' && component.name === ''

return (isClassComponent || isFunctionalComponent) && !isAnonymousFunction
const isRSC = isFunctionalComponent && !isAnonymousFunction && !hasClientComponentSymbol

return isRSC
}

export function isReactClientComponent<T extends any>(
component: React.ComponentType | any,
): component is T {
const isClientComponentWebpack = typeof component === 'object' && !isPlainObject(component) // In Webpack, client components are {}
const isClientComponentTurbo = typeof component === 'function' && component.name === '' // Anonymous functions are Client Components in Turbopack

return isClientComponentWebpack || isClientComponentTurbo
if (component === null || component === undefined) {
return false
}
return !isReactServerComponentOrFunction(component) && component.$$typeof == clientRefSymbol
}

export function isReactComponentOrFunction<T extends any>(
Expand Down
2 changes: 1 addition & 1 deletion packages/ui/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@
"turbopack": "^0.0.1"
},
"peerDependencies": {
"next": "^15.0.0-rc.0",
"next": "^15.0.0-canary.53",
"payload": "workspace:*",
"react": "^19.0.0 || ^19.0.0-rc-f994737d14-20240522",
"react-dom": "^19.0.0 || ^19.0.0-rc-f994737d14-20240522"
Expand Down
116 changes: 60 additions & 56 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading