-
Notifications
You must be signed in to change notification settings - Fork 2.3k
fix(useDocumentInfo): Add explicit null to types #9030
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
base: 2.x
Are you sure you want to change the base?
Conversation
I think we need to wait and review this change after the RSC refactor PR because the DocumentInfoProvider is undering major changes right now. |
This is for the v2 branch. Are you going to push RSC to the v2 branch? |
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 for the v2 branch. Are you going to push RSC to the v2 branch?
I missed that the target branch is main
on this. Unfortunately we need to avoid breaking changes so I don't think we can merge this as-is. Even if the types should technically have a union null it could cause existing 2.x projects to not build by changing it now.
The only options are to migrate to 3.x or we would have to a nasty option flag or make a separate function for useDocumentInfo that could make this type change only for the new properties.
Can this be released as a minor version (not a patch version) so that users are informed about a possible breakage? This doesn't cause new runtime issues; it simply surfaces potential issues that already exist in the system. AFAIK V3 is still in beta, so it's not an option for us to migrate. |
No, following semantic versioning, we can only make breaking changes in major versions. We have been reprimanded by the community for this in the past. You could add a custom provider in your own config that simply gets the |
I think we should normalize the use of future flags though I understand if this isn't on the team's appetite for v2. |
import { useDocumentInfo as useDocumentInfo_ORIGINAL } from 'payload/components/utilities';
type DocumentInfo = ReturnType<typeof useDocumentInfo_ORIGINAL>;
const ALL_MISTYPED_PROPS = [
'versions',
'publishedDoc',
'unpublishedVersions',
] as const satisfies (keyof DocumentInfo)[];
type MistypedProps = (typeof ALL_MISTYPED_PROPS)[number];
export const useDocumentInfo: (...args: Parameters<typeof useDocumentInfo_ORIGINAL>) => Omit<
DocumentInfo,
MistypedProps
> & {
[P in MistypedProps]?: Required<DocumentInfo>[P] | null;
} = useDocumentInfo_ORIGINAL; |
What?
Added
| null
to the type for context props initialized tonull
.Why?
For code bases using a more strict typescript configuration,
null
andundefined
(and optional fields) are different types and require handling separately. The states for these three context fields are all initialized tonull
, but their type doesn't include that. This caused runtime errors in our codebase.How?
Modified the type, both in the context type, and in the react setters. Notice that this change doesn't change anything in the runtime behaviour of the code, just types.