π₯ Make videos programmatically with React
article about using background-image
Jonny Burger53a259719108
diff --git a/packages/docs/docs/troubleshooting/background-image.md b/packages/docs/docs/troubleshooting/background-image.mdnew file mode 100644index 0000000000..aa63bc64ef--- /dev/null+++ b/packages/docs/docs/troubleshooting/background-image.md@@ -0,0 +1,57 @@+---+image: /generated/articles-docs-troubleshooting-background-image.png+sidebar_label: Flickering with background-image+title: Flickering when using background-image+crumb: "Common mistakes"+---++The following code is discouraged in Remotion:++```tsx twoslash title="β Don't do this"+const src = "abc";+// ---cut---+const myMarkup = (+ <div+ style={{+ backgroundImage: `url(${src})`,+ }}+ >+ <p>Hello World</p>+ </div>+);+```++## Problem++Remotion has no way of knowing when the image is finished loading because it is impossible to determine so when loading an image through `background-image`. This will lead to Remotion not waiting for the image to be loaded during rendering and cause visible flickers.++## Solution++Use the [`<Img>`](/docs/img) tag instead and place it in an [`<AbsoluteFill>`](/docs/absolute-fill):++```tsx twoslash title="β Do this"+const src = "abc";+// ---cut---+import { AbsoluteFill, Img } from "remotion";++const myMarkup = (+ <AbsoluteFill>+ <AbsoluteFill>+ <Img+ style={{+ width: "100%",+ }}+ src={src}+ />+ </AbsoluteFill>+ <AbsoluteFill>+ <p>Hello World</p>+ </AbsoluteFill>+ </AbsoluteFill>+);+```++## See also++- [`<Img>`](/docs/img)+- [Flickering](/docs/flickering)diff --git a/packages/docs/sidebars.js b/packages/docs/sidebars.jsindex c3e76f609e..f487e7574b 100644--- a/packages/docs/sidebars.js+++ b/packages/docs/sidebars.js@@ -431,6 +431,7 @@ module.exports = {"wrong-composition-mount","staticfile-relative-paths","staticfile-remote-urls",+ "troubleshooting/background-image","troubleshooting/rosetta","troubleshooting/loading-root-component","troubleshooting/defaultprops-too-big",diff --git a/packages/docs/src/data/articles.ts b/packages/docs/src/data/articles.tsindex 466778e4fb..4cd5a8e8ee 100644--- a/packages/docs/src/data/articles.ts+++ b/packages/docs/src/data/articles.ts@@ -1716,6 +1716,13 @@ export const articles = [compId: "articles-docs-transparent-videos",crumb: "Techniques",},+ {+ id: "troubleshooting/background-image",+ title: "Flickering when using background-image",+ relativePath: "docs/troubleshooting/background-image.md",+ compId: "articles-docs-troubleshooting-background-image",+ crumb: "Common mistakes",+ },{id: "defaultprops-too-big",title: "defaultProps too big - could not serialize",diff --git a/packages/docs/static/generated/articles-docs-troubleshooting-background-image.png b/packages/docs/static/generated/articles-docs-troubleshooting-background-image.pngnew file mode 100644index 0000000000..ae2c610159Binary files /dev/null and b/packages/docs/static/generated/articles-docs-troubleshooting-background-image.png differ