refactor: Extend PayloadMediaProps with HTML media element attributes#439
refactor: Extend PayloadMediaProps with HTML media element attributes#439ainsleyclark merged 3 commits intomainfrom
Conversation
…ompatibility - Make Media.alt nullable (string | null) to match Payload-generated types - Extend PayloadMediaProps with HTMLVideoAttributes, HTMLImgAttributes, and HTMLPictureAttributes so video props (autoplay, muted, loop, playsinline, controls, preload) and img/picture props (srcset, sizes, decoding) can be spread onto the rendered element https://claude.ai/code/session_01JsPYAtAnEtvcMbfWA1tEyz
This comment has been minimized.
This comment has been minimized.
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: b49991343e
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| >; | ||
|
|
||
| export type PayloadMediaProps = HTMLAttributes<HTMLElement> & { | ||
| export type PayloadMediaProps = HTMLAttributes<HTMLElement> & HTMLVideoAttributes & HTMLImgAttributes & HTMLPictureAttributes & { |
There was a problem hiding this comment.
Remove unsupported img attrs from public props
Adding HTMLImgAttributes to PayloadMediaProps makes callers believe image-specific props (for example decoding, fetchpriority, referrerpolicy) will be forwarded, but in the normal image path restProps is spread onto <picture> while the inner <img> does not receive ...restProps (PayloadMedia.svelte non-SVG branch). This means those newly-accepted props are silently ignored for most images, which is a behavioural regression introduced by this type change.
Useful? React with 👍 / 👎.
Review summary
Small, focused change that addresses a real gap. The Critical issues 🔴None Warnings 🟡1. Type intersection may produce Intersecting Since the component conditionally renders one element type at a time ( Suggested alternativeexport type PayloadMediaBaseProps = {
data: Media;
loading?: 'lazy' | 'eager' | undefined;
className?: string;
breakpointBuffer?: number;
maxWidth?: number | undefined;
onload?: (event: Event) => void;
};
export type PayloadMediaProps =
| (PayloadMediaBaseProps & HTMLVideoAttributes)
| (PayloadMediaBaseProps & HTMLImgAttributes)
| (PayloadMediaBaseProps & HTMLPictureAttributes);This correctly models "one of these three element types" and avoids the intersection narrowing issue. 2.
Suggestions 🟢1. Pre-existing, but worth noting: in |
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #439 +/- ##
==========================================
+ Coverage 64.59% 70.26% +5.67%
==========================================
Files 154 187 +33
Lines 6064 7439 +1375
==========================================
+ Hits 3917 5227 +1310
+ Misses 2064 2012 -52
- Partials 83 200 +117 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
Summary
Enhanced the
PayloadMediaPropstype to support a broader range of HTML media element attributes by intersecting with native HTML attribute types for video, image, and picture elements. Also updated theMediatype to allownullvalues for thealtproperty.Key Changes
HTMLVideoAttributes,HTMLImgAttributes, andHTMLPictureAttributesfromsvelte/elementsPayloadMediaPropsto intersect withHTMLVideoAttributes,HTMLImgAttributes, andHTMLPictureAttributesin addition to the existingHTMLAttributes<HTMLElement>Media.altproperty type fromstring | undefinedtostring | nullfor more explicit null handlingImplementation Details
These changes allow the
PayloadMediaPropstype to properly support attributes specific to video, img, and picture HTML elements, providing better type safety and IDE autocomplete when using media components with these native HTML attributes. Thealtproperty change aligns with how Payload CMS handles optional string fields that can be explicitly set to null.https://claude.ai/code/session_01JsPYAtAnEtvcMbfWA1tEyz