fix: media preview bug when zero size, close #764
Description
Close #764
Linked Issues
#764
Additional context
@cesaryuan is attempting to deploy a commit to the RSS3 Team on Vercel.
A member of the Team first needs to authorize it.
/ai-review
Suggested PR Title: feat(media): improve preview media component with height and width validation
Code Review:
-
apps/renderer/src/components/ui/media/preview-media.tsx:291
-
Issue:
Number.parseInt(props.height as string)assumes thatprops.heightis always a string or can be cast to a string. This can result in unexpected behavior or errors ifprops.heightis not a string. -
Change Request: Validate that
props.heightis indeed a string before attempting to parse it. Alternatively, handle cases whereprops.heightmight not be a string.
-
Issue:
-
apps/renderer/src/components/ui/media/preview-media.tsx:292
-
Issue:
Number.parseInt(props.width as string)has the same issue as above, assumingprops.widthcan always be cast to a string. -
Change Request: Validate
props.widthsimilarly to ensure it's a string before parsing.
-
Issue:
-
apps/renderer/src/components/ui/media/preview-media.tsx:299
-
Issue: The check
height === 0 || width === 0does not account for logical errors where one value might be zero and the other is valid, potentially resulting in incorrect styles applied. - Change Request: Consider refining the condition to handle these cases more robustly, ensuring the style is applied correctly based on valid height and width.
-
Issue: The check
-
apps/renderer/src/components/ui/media/preview-media.tsx:299-300
-
Issue: The check
Number.isNaN(height) || Number.isNaN(width)would work correctly only ifheightandwidthare intended to be numbers. However, the code does not handle default cases whereprops.heightorprops.widthmight be missing or default to a non-numeric value. -
Change Request: Add default values or further validation to ensure
heightandwidthare valid numbers before performing these checks. Add fallback/default values for cases where parameters might be missing.
-
Issue: The check
These changes will ensure the code handles various edge cases and unexpected input types more robustly.