Skip to content

fix(plugin-redirects): add missing optional chaining #12753

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

Conversation

Patrickroelofs
Copy link
Contributor

What?

Updates the redirects plugin types to make collections a required type

Why?

Currently not including the collections object when importing the plugin causes an error to occur when going to the page in the UI, also it cannot generate types. Likely due to it unable to make a reference to a collection.

How?

Makes collections required

Fixes #12709

@Patrickroelofs
Copy link
Contributor Author

Alternatively, we could also hide the "internal link" option when no collection has been supplied, if that is the preferred solution let me know

image

Copy link
Contributor

@GermanJablo GermanJablo left a comment

Choose a reason for hiding this comment

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

Thanks for the PR.
This is a breaking change. The correct solution would be to check for the existence of collections where it's used. Probably an if or optional chaining in the plugin.

@Patrickroelofs
Copy link
Contributor Author

I will have a look, thanks for the feedback!

@GermanJablo
Copy link
Contributor

Thank you. I hadn't read your next comment, but it makes sense to me:

Alternatively, we could also hide the "internal link" option when no collection has been supplied, if that is the preferred solution let me know

Please ask me to review it when it's ready.

@Patrickroelofs
Copy link
Contributor Author

Patrickroelofs commented Jun 11, 2025

Hey @GermanJablo

I managed to debug and figure out what the issue actually was, it seemed to be a translation in the AddNewRelation element. I tested both an empty and filled array, let me know if I can improve it further, I've seen some optional chaining like this in a few other translations so it seemed fine to me!

This change is however not restricted to only the plugin, so let me know what I should do.

This is my first contribution so I apologize for some hand holding.

@GermanJablo GermanJablo changed the title fix(plugin-redirects): change collections from optional to required fix(plugin-redirects): add missing optional chaining Jun 11, 2025
Copy link
Contributor

@GermanJablo GermanJablo left a comment

Choose a reason for hiding this comment

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

Thank you!

@GermanJablo GermanJablo enabled auto-merge (squash) June 11, 2025 16:49
@GermanJablo GermanJablo merged commit d0e647a into payloadcms:main Jun 12, 2025
79 checks passed
@Patrickroelofs Patrickroelofs deleted the fix/plugin-redirect-required-collections branch June 12, 2025 16:44
Copy link
Contributor

🚀 This is included in version v3.43.0

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

@payloadcms/plugin-redirects - generate:types no longer working because of prettier error
3 participants