Skip to content

πŸŽ₯ Make videos programmatically with React

Add a standalone production Sequence retention reproduction

Alec Watts791ef6e5ab13
diff --git a/repros/sequence-child-retention/README.md b/repros/sequence-child-retention/README.md
new file mode 100644
index 0000000000..04c417f7e2
--- /dev/null
+++ b/repros/sequence-child-retention/README.md
@@ -0,0 +1,21 @@
+# Sequence retains a replaced child
+
+Copy this folder outside the Remotion checkout, then run:
+
+```sh
+bun install
+bun run build
+bun run preview
+```
+
+Open http://127.0.0.1:4178 in Chrome. Use the production build above: development React can retain debug owners independently of this bug.
+
+1. Click **Replace child five times** and wait for the completion message.
+2. Open DevTools β†’ Memory and click **Collect garbage**.
+3. Click **Inspect retained revisions**.
+
+Only child 5 is still rendered, so the expected result is `[5]`. The affected implementation retains child 0 as well: `[0,5]`. Each child function captures a 1 MiB buffer. The array stores only weak references to these functions.
+
+The extra two commits after replacement flush React's current and alternate trees. After clicking **Unmount Player** and collecting garbage again, the expected result is `[]`.
+
+This measures JavaScript reachability after explicit GC. It does not measure process memory or assume when automatic GC will run.
diff --git a/repros/sequence-child-retention/index.html b/repros/sequence-child-retention/index.html
new file mode 100644
index 0000000000..9ed96ac494
--- /dev/null
+++ b/repros/sequence-child-retention/index.html
@@ -0,0 +1,16 @@
+<!doctype html>
+<html lang="en">
+ <meta charset="UTF-8" />
+ <title>Sequence child retention</title>
+ <h1>Sequence child retention</h1>
+ <p>
+ Replace the child, use Chrome's Memory panel to collect garbage, then
+ inspect retained revisions.
+ </p>
+ <button id="replace">Replace child five times</button>
+ <button id="inspect">Inspect retained revisions</button>
+ <button id="unmount">Unmount Player</button>
+ <pre id="result">Current revision: 0</pre>
+ <div id="root"></div>
+ <script type="module" src="/main.jsx"></script>
+</html>
diff --git a/repros/sequence-child-retention/main.jsx b/repros/sequence-child-retention/main.jsx
new file mode 100644
index 0000000000..1eb55f1f05
--- /dev/null
+++ b/repros/sequence-child-retention/main.jsx
@@ -0,0 +1,71 @@
+import {Player} from '@remotion/player';
+import React, {useLayoutEffect, useState} from 'react';
+import {createRoot} from 'react-dom/client';
+import {Sequence} from 'remotion';
+
+const refs = [];
+const makeChild = (revision) => {
+ const buffer = new Uint8Array(1024 * 1024);
+ buffer[0] = revision;
+ const Child = () => <span>Current revision: {buffer[0]}</span>;
+ refs.push(new WeakRef(Child));
+ return Child;
+};
+
+let replace;
+let flush;
+const Composition = () => {
+ const [state, setState] = useState(() => ({Child: makeChild(0), tick: 0}));
+ useLayoutEffect(() => {
+ replace = (revision) =>
+ setState({Child: makeChild(revision), tick: revision});
+ flush = () => setState((current) => ({...current, tick: current.tick + 1}));
+ return () => {
+ replace = null;
+ flush = null;
+ };
+ }, []);
+ return (
+ <Sequence layout="none">
+ <state.Child />
+ </Sequence>
+ );
+};
+
+const root = createRoot(document.getElementById('root'));
+root.render(
+ <Player
+ component={Composition}
+ durationInFrames={100}
+ fps={30}
+ compositionWidth={320}
+ compositionHeight={100}
+ />,
+);
+
+const afterCommit = () =>
+ new Promise((resolve) =>
+ requestAnimationFrame(() => requestAnimationFrame(resolve)),
+ );
+window.retainedRevisions = () =>
+ refs.flatMap((ref, index) => (ref.deref() ? [index] : []));
+document.getElementById('replace').onclick = async () => {
+ document.getElementById('replace').disabled = true;
+ for (let revision = 1; revision <= 5; revision++) {
+ replace(revision);
+ await afterCommit();
+ }
+ // Commit twice more so both current and alternate React trees have child 5.
+ for (let i = 0; i < 2; i++) {
+ flush();
+ await afterCommit();
+ }
+ document.getElementById('result').textContent =
+ 'Replacement complete. Collect garbage, then inspect.';
+};
+document.getElementById('inspect').onclick = () => {
+ document.getElementById('result').textContent = JSON.stringify(
+ window.retainedRevisions(),
+ );
+};
+document.getElementById('unmount').onclick = () => root.unmount();
diff --git a/repros/sequence-child-retention/package.json b/repros/sequence-child-retention/package.json
new file mode 100644
index 0000000000..ba68d07936
--- /dev/null
+++ b/repros/sequence-child-retention/package.json
@@ -0,0 +1,18 @@
+{
+ "name": "sequence-child-retention-repro",
+ "private": true,
+ "type": "module",
+ "scripts": {
+ "build": "vite build",
+ "preview": "vite preview --host 127.0.0.1 --port 4178"
+ },
+ "dependencies": {
+ "@remotion/player": "4.0.537",
+ "react": "19.2.3",
+ "react-dom": "19.2.3",
+ "remotion": "4.0.537"
+ },
+ "devDependencies": {
+ "vite": "6.4.4"
+ }
+}
diff --git a/repros/sequence-child-retention/vite.config.js b/repros/sequence-child-retention/vite.config.js
new file mode 100644
index 0000000000..823f1882c8
--- /dev/null
+++ b/repros/sequence-child-retention/vite.config.js
@@ -0,0 +1 @@
+export default {build: {minify: false}};