Folo icon indicating copy to clipboard operation
Folo copied to clipboard

fix: media preview bug when zero size, close #764

Open cesaryuan opened this issue 1 year ago • 1 comments

Description

Close #764

Linked Issues

#764

Additional context

cesaryuan avatar Oct 05 '24 12:10 cesaryuan

@cesaryuan is attempting to deploy a commit to the RSS3 Team on Vercel.

A member of the Team first needs to authorize it.

vercel[bot] avatar Oct 05 '24 12:10 vercel[bot]

/ai-review

Innei avatar Oct 07 '24 12:10 Innei

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 that props.height is always a string or can be cast to a string. This can result in unexpected behavior or errors if props.height is not a string.
    • Change Request: Validate that props.height is indeed a string before attempting to parse it. Alternatively, handle cases where props.height might not be a string.
  • apps/renderer/src/components/ui/media/preview-media.tsx:292

    • Issue: Number.parseInt(props.width as string) has the same issue as above, assuming props.width can always be cast to a string.
    • Change Request: Validate props.width similarly to ensure it's a string before parsing.
  • apps/renderer/src/components/ui/media/preview-media.tsx:299

    • Issue: The check height === 0 || width === 0 does 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.
  • apps/renderer/src/components/ui/media/preview-media.tsx:299-300

    • Issue: The check Number.isNaN(height) || Number.isNaN(width) would work correctly only if height and width are intended to be numbers. However, the code does not handle default cases where props.height or props.width might be missing or default to a non-numeric value.
    • Change Request: Add default values or further validation to ensure height and width are valid numbers before performing these checks. Add fallback/default values for cases where parameters might be missing.

These changes will ensure the code handles various edge cases and unexpected input types more robustly.