Skip to content

🎥 Make videos programmatically with React

`@remotion/player`: Fix `marginLeft` being NaN

Jonny Burger2c5172585057
diff --git a/packages/docs/src/components/Demo/use-element-size.ts b/packages/docs/src/components/Demo/use-element-size.ts
index 71d12e7ff8..5094fd03bd 100644
--- a/packages/docs/src/components/Demo/use-element-size.ts
+++ b/packages/docs/src/components/Demo/use-element-size.ts
@@ -74,12 +74,14 @@ export const useElementSize = (
const probableCssParentScale =
contentRect.width === 0 ? 1 : newSize[0].width / contentRect.width;
- const width = options.shouldApplyCssTransforms
- ? newSize[0].width
- : newSize[0].width * (1 / probableCssParentScale);
- const height = options.shouldApplyCssTransforms
- ? newSize[0].height
- : newSize[0].height * (1 / probableCssParentScale);
+ const width =
+ options.shouldApplyCssTransforms && probableCssParentScale > 0
+ ? newSize[0].width
+ : newSize[0].width * (1 / probableCssParentScale);
+ const height =
+ options.shouldApplyCssTransforms && probableCssParentScale > 0
+ ? newSize[0].height
+ : newSize[0].height * (1 / probableCssParentScale);
setSize({
width,
diff --git a/packages/gif/src/use-element-size.ts b/packages/gif/src/use-element-size.ts
index 660c8b339f..06868b8e62 100644
--- a/packages/gif/src/use-element-size.ts
+++ b/packages/gif/src/use-element-size.ts
@@ -35,10 +35,17 @@ export const useElementSize = (
return;
}
- const probableCssParentScale = newSize[0].width / contentRect.width;
-
- const width = newSize[0].width * (1 / probableCssParentScale);
- const height = newSize[0].height * (1 / probableCssParentScale);
+ const probableCssParentScale =
+ contentRect.width === 0 ? 1 : newSize[0].width / contentRect.width;
+
+ const width =
+ probableCssParentScale > 0
+ ? newSize[0].width * (1 / probableCssParentScale)
+ : newSize[0].width;
+ const height =
+ probableCssParentScale > 0
+ ? newSize[0].height * (1 / probableCssParentScale)
+ : newSize[0].height;
setSize({
width,
diff --git a/packages/player/src/utils/use-element-size.ts b/packages/player/src/utils/use-element-size.ts
index 62de39ff90..e30155adfb 100644
--- a/packages/player/src/utils/use-element-size.ts
+++ b/packages/player/src/utils/use-element-size.ts
@@ -72,13 +72,12 @@ export const useElementSize = (
}
const probableCssParentScale =
- contentRect.width === 0 || contentRect.width === 0
- ? 1
- : newSize[0].width / contentRect.width;
+ contentRect.width === 0 ? 1 : newSize[0].width / contentRect.width;
- const width = options.shouldApplyCssTransforms
- ? newSize[0].width
- : newSize[0].width * (1 / probableCssParentScale);
+ const width =
+ options.shouldApplyCssTransforms && probableCssParentScale > 0
+ ? newSize[0].width
+ : newSize[0].width * (1 / probableCssParentScale);
const height = options.shouldApplyCssTransforms
? newSize[0].height
: newSize[0].height * (1 / probableCssParentScale);