-
Notifications
You must be signed in to change notification settings - Fork 2k
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
+83
−101
Merged
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
8cc5614
fix(next): server-only props were passed to Document Views
AlessioGr 6140463
fix: RSC detection in new Next.js versions
AlessioGr 7660f90
feat!: upgrade minimum required Next.js version to 15.0.0-canary.53
AlessioGr e3733fd
chore: handle null or undefined components in RSC detection
AlessioGr 926cbeb
fix: objects being detected as client components even though they're …
AlessioGr File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
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
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
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,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') | ||
|
||
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 | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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>( | ||
|
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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is soo nice