payload icon indicating copy to clipboard operation
payload copied to clipboard

feat!: fix non-functional custom RSC component handling, separate label and description props, fix non-functional label function handling

Open AlessioGr opened this issue 1 year ago • 0 comments

Description

RSC Custom Components fix

The goal for custom components is to pass in payload if they are server components. This never happened, as our logic for detecting RSCs was broken. This is now fixed.

Additionally, the BeforeLogin and AfterLogin custom components are now handled properly, which allows us to inject the payload prop into them if they are RSCs.

Labels fix

Currently, admin.description (for fields) can be a

  • string
  • function (with t as argument) which returns string
  • Client Component
  • RSC

The problem: there is no reliable way to discern between functions and RSCs.

If it is a function returning a string, we want to insert it as text into the default Description component.

If it is a RSC, we want to completely replace the default Description component.

Solution: We have separated the props

We already have admin.components. So we split up admin.description into:

admin.description - now only accepts string or function returning a string admin.components.Description - accepts RSC or Client Component

More details on the specific changes are in the breaking changes list.

Additionally, the globalConfig.admin.description and collectionConfig.admin.description functions now have access to the t prop.

Broken i18n label functions

CleanShot 2024-05-08 at 19 22 30

This used the sanitized field name (Url) as the label, as fields:enterURL was never resolved. So yea, any custom label function which used the t function like that did not work.

Breaking Changes

  • Globals config: admin.description no longer accepts a custom component. You will have to move it to admin.components.elements.Description
  • Collections config: admin.description no longer accepts a custom component. You will have to move it to admin.components.edit.Description
  • All Fields: field.admin.description no longer accepts a custom component. You will have to move it to field.admin.components.Description
  • Collapsible Field: field.label no longer accepts a custom component. You will have to move it to field.admin.components.RowLabel
  • Array Field: field.admin.components.RowLabel no longer accepts strings or records
  • If you are using our exported field components in your own app, their labelProps property has been stripped down and no longer contains the label and required prop. Those can now only be configured at the top-level
  • [ ] I have read and understand the CONTRIBUTING.md document in this repository.

Type of change

  • [ ] Chore (non-breaking change which does not add functionality)
  • [ ] Bug fix (non-breaking change which fixes an issue)
  • [ ] New feature (non-breaking change which adds functionality)
  • [X] Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • [ ] Change to the templates directory (does not affect core functionality)
  • [ ] Change to the examples directory (does not affect core functionality)
  • [ ] This change requires a documentation update

Checklist:

  • [ ] I have added tests that prove my fix is effective or that my feature works
  • [ ] Existing test suite passes locally with my changes
  • [ ] I have made corresponding changes to the documentation

AlessioGr avatar May 08 '24 14:05 AlessioGr