Skip to content

🎥 Make videos programmatically with React

handle player and SSR cases

Jonny Burger13262d701e18
diff --git a/packages/core/src/get-static-files.ts b/packages/core/src/get-static-files.ts
index 0f8f2738f0..14c0e40150 100644
--- a/packages/core/src/get-static-files.ts
+++ b/packages/core/src/get-static-files.ts
@@ -1,5 +1,40 @@
import type {StaticFile} from './static-file';
+let warnedServer = false;
+let warnedPlayer = false;
+
+const warnServerOnce = () => {
+ if (warnedServer) {
+ return;
+ }
+
+ warnedServer = true;
+ console.warn(
+ 'Called getStaticFiles() on the server. The API is only available in the browser. An empty array was returned.'
+ );
+};
+
+const warnPlayerOnce = () => {
+ if (warnedPlayer) {
+ return;
+ }
+
+ warnedPlayer = true;
+ console.warn(
+ 'Called getStaticFiles() while using the Remotion Player. The API is only available while using the Remotion Preview. An empty array was returned.'
+ );
+};
+
export const getStaticFiles = (): StaticFile[] => {
+ if (typeof document === 'undefined') {
+ warnServerOnce();
+ return [];
+ }
+
+ if (window.remotion_isPlayer) {
+ warnPlayerOnce();
+ return [];
+ }
+
return window.remotion_staticFiles;
};