-
Notifications
You must be signed in to change notification settings - Fork 1.9k
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!: component paths #7246
Merged
Merged
feat!: component paths #7246
Conversation
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
…fully type-safe way
…. ServerSideEditViewProps) are passed and then make it to non-function-argument props
…r plugins and richText adapters
AlessioGr
changed the title
WIP: component paths
feat!: fully server-side payload config, component paths instead of imports
Jul 30, 2024
jacobsfletch
changed the title
feat!: fully server-side payload config, component paths instead of imports
feat!: component paths
Aug 2, 2024
jacobsfletch
added a commit
that referenced
this pull request
Dec 20, 2024
The auth example was still on `v3.0.0-beta.24`, was missing its users collection config, and was not yet using the component paths pattern established here: #7246. This updates to latest and fixes these issues. This example can still use further improvements and housekeeping which will come in future PRs.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
This PR ensures that the payload config is 100% server-only. Instead of importing custom components into your config directly, they are now defined as file paths and rendered only when needed. That way, the payload 3.0 release does not rely on vercel/next.js#65415 which will likely will not get merged. Now, the Payload config will be significantly more lightweight.
Related discussion: #6938
The issue
This PR fixes a few issues:
#4085 #6598 #6441 #7261 #7339
Local API within Next.js routes
Previously, if you used the payload local API within Next.js pages, all the client-side modules are being added to the bundle for that specific page, even if you only need server-side functionality.
This
/test
route, which uses the payload local API, was previously 460 kb. It is now down to 91 kb and does not bundle the payload client-side admin panel anymore.All tests done here with beta.67/PR, db-mongodb and default richtext-lexical:
dev /admin before:
dev /admin after:
dev /test before:
dev /test after:
build before:
build after::
Usage of the payload local API / config outside of Next.js
This will make it a lot easier to use the payload config / local API in other, server-side contexts. Previously, you might encounter errors due to client files (like .scss files) not being allowed to be imported.
Custom Client Components are not server-rendered anymore
Previously, custom components would be server-rendered in
buildComponentMap
, no matter if they are server or client components. Now, only server components are rendered inbuildComponentMap
. Client components simply get passed through, usingMappedComponent
as a container. It is then the client's responsibility to render those.This makes rendering them on the client a little bit more complex, as you now have to check if that component is a server component (=> already has been rendered) or a client component (=> not rendered yet, has to be rendered here). However, this added complexity has been alleviated through the easy-to-use
<RenderMappedComponent />
helper.This helper now also handles rendering arrays of custom components (e.g. beforeList, beforeLogin ...), which actually makes rendering custom components easier in some cases.
The benefit of this change:
Custom client components can now receive props. Previously, the only way for them to receive dynamic props from a parent client component was to use hooks, e.g.
useFieldProps()
. Now, we do have the option of passing in props to the custom components directly, if they are client components. This will be simpler than having to look for the correct hook,Misc improvements
This PR includes misc, breaking changes. For example, we previously allowed unions between components and config object for the same property. E.g. for the custom view property, you were allowed to pass in a custom component or an object with other properties, alongside a custom component.
Those union types are now gone. You can now either pass an object, or a component. The previous
{ View: MyViewComponent}
is now{ View: { Component: MyViewComponent} }
or{ View: { Default: { Component: MyViewComponent} } }
.This dramatically simplifies the way we read & process those properties, especially in buildComponentMap. We can now simply check for the existence of one specific property, which always has to be a component, instead of running cursed runtime checks on a shared union property which could contain a component, but could also contain functions or objects.
Custom Components
In order to reference any custom components in the payload config, you now have to specify a string path to the component instead of importing it.
E.g.
Now becomes:
Concepts: MappedComponent and PayloadComponent
Instead of
React.FC
/React.ComponentType
, props within the payload config that accept components now acceptPayloadComponent
. These are basically the paths to the component. They can be a string, or an object containing other properties like serverProps and clientProps - giving you full control over the props this component will eventually receive.MappedComponent
is the result of buildComponentMap processing all thosePayloadComponent
s. It contains the server-rendered component, or unrendered/rendered client component. AnyMappedComponent
can be rendered on both either the client and the server using theRenderMappedComponent
helper component.Try it out
This can be tested out here: https://github.com/payloadcms/payload-3.0-demo/tree/feat/path-test
Todo