Skip to content

🎥 Make videos programmatically with React

Remove asset URL cache-busting query strings

Igor Samokhovetsca374b28750b
diff --git a/packages/core/src/input-props-serialization.ts b/packages/core/src/input-props-serialization.ts
index 6f7d5de239..a726650b3a 100644
--- a/packages/core/src/input-props-serialization.ts
+++ b/packages/core/src/input-props-serialization.ts
@@ -1,7 +1,6 @@
// Must keep this file in sync with the one in packages/lambda/src/shared/serialize-props.ts!
import {getRemotionEnvironment} from './get-remotion-environment.js';
-import {getStaticFileUrl} from './static-file.js';
export type SerializedJSONWithCustomFields = {
serializedString: string;
@@ -55,7 +54,7 @@ export const serializeJSONWithSpecialTypes = ({
item.startsWith(staticBase)
) {
customFileUsed = true;
- return `${FILE_TOKEN}${item.replace(staticBase + '/', '').split('?')[0]}`;
+ return `${FILE_TOKEN}${item.replace(staticBase + '/', '')}`;
}
return value;
@@ -72,7 +71,7 @@ export const serializeJSONWithSpecialTypes = ({
};
export const resolveFileTokenToUrl = (value: string) => {
- const encodedName = value.replace(FILE_TOKEN, '').split('?')[0];
+ const encodedName = value.replace(FILE_TOKEN, '');
let name = encodedName;
try {
name = encodedName.split('/').map(decodeURIComponent).join('/');
@@ -87,7 +86,7 @@ export const resolveFileTokenToUrl = (value: string) => {
return matchingStaticFile.src;
}
- return getStaticFileUrl(encodedName);
+ return `${window.remotion_staticBase}/${encodedName}`;
};
export const deserializeJSONWithSpecialTypes = <T = Record<string, unknown>>(
diff --git a/packages/core/src/static-file.ts b/packages/core/src/static-file.ts
index 66c7e694ea..35e0117581 100644
--- a/packages/core/src/static-file.ts
+++ b/packages/core/src/static-file.ts
@@ -60,7 +60,7 @@ const trimLeadingSlash = (path: string): string => {
return path;
};
-export const getStaticFileUrl = (path: string): string => {
+const inner = (path: string): string => {
if (typeof window !== 'undefined' && window.remotion_staticBase) {
if (path.startsWith(window.remotion_staticBase)) {
throw new Error(
@@ -68,10 +68,7 @@ export const getStaticFileUrl = (path: string): string => {
);
}
- const src = `${window.remotion_staticBase}/${trimLeadingSlash(path)}`;
- return window.remotion_outputsBase
- ? `${src}?v=${encodeURIComponent(window.remotion_outputsBase)}`
- : src;
+ return `${window.remotion_staticBase}/${trimLeadingSlash(path)}`;
}
return `/${trimLeadingSlash(path)}`;
@@ -143,8 +140,8 @@ export const staticFile = (path: string) => {
if (typeof window !== 'undefined') {
// This lookup is primarily used by Browser Studio, where virtual assets
- // have blob: URLs. Regular Studio sources include the per-start cache
- // version and use the same per-path-segment encoding as the fallback below.
+ // have blob: URLs. Regular Studio sources are already encoded using the
+ // same per-path-segment encoding as the fallback below.
const matchingStaticFile = window.remotion_staticFiles?.find(
(file) => file.name === trimLeadingSlash(path),
);
@@ -154,7 +151,7 @@ export const staticFile = (path: string) => {
}
const preprocessed = encodeBySplitting(path);
- const preparsed = getStaticFileUrl(preprocessed);
+ const preparsed = inner(preprocessed);
if (!preparsed.startsWith('/')) {
return `/${preparsed}`;
diff --git a/packages/core/src/watch-static-file.ts b/packages/core/src/watch-static-file.ts
index 48f401a434..6002d7bd3c 100644
--- a/packages/core/src/watch-static-file.ts
+++ b/packages/core/src/watch-static-file.ts
@@ -33,13 +33,9 @@ export const watchStaticFile = (
return {cancel: () => undefined};
}
- const withoutStaticBase =
- window.remotion_staticBase &&
- fileName.startsWith(window.remotion_staticBase + '/')
- ? decodeURIComponent(
- fileName.slice(window.remotion_staticBase.length).split('?')[0],
- )
- : fileName;
+ const withoutStaticBase = fileName.startsWith(window.remotion_staticBase)
+ ? fileName.replace(window.remotion_staticBase, '')
+ : fileName;
const withoutLeadingSlash = withoutStaticBase.startsWith('/')
? withoutStaticBase.slice(1)
: withoutStaticBase;
diff --git a/packages/example/e2e/static-file-restart.test.mts b/packages/example/e2e/static-file-restart.test.mts
index f763b5220b..c93abe4075 100644
--- a/packages/example/e2e/static-file-restart.test.mts
+++ b/packages/example/e2e/static-file-restart.test.mts
@@ -6,7 +6,7 @@ import path from 'node:path';
import {expect, test} from '@playwright/test';
import {exampleDir, remotionBin} from './constants.mts';
-test('static assets survive Studio restarts while replacements bypass old cache keys', async ({
+test('static assets survive Studio restarts and serve replacement files', async ({
page,
}) => {
test.setTimeout(120_000);
@@ -110,7 +110,7 @@ registerRoot(Root);
await writeFile(path.join(publicDir, assetName), replacement);
await start();
- // An already-open Studio can still request its old versioned URL.
+ // An already-open Studio can still request its original asset URL.
const oldResponse = await page.request.get(oldUrl);
expect(oldResponse.status()).toBe(200);
expect(await oldResponse.body()).toEqual(replacement);
@@ -120,8 +120,8 @@ registerRoot(Root);
const newUrl = await image.evaluate(
(element) => (element as HTMLImageElement).src,
);
- expect(new URL(newUrl).pathname).toBe(new URL(oldUrl).pathname);
- expect(new URL(newUrl).search).not.toBe(new URL(oldUrl).search);
+ expect(newUrl.endsWith('.png')).toBe(true);
+ expect(newUrl).toBe(oldUrl);
} finally {
await stop();
await rm(fixture, {recursive: true, force: true});
diff --git a/packages/studio-server/src/preview-server/public-folder.ts b/packages/studio-server/src/preview-server/public-folder.ts
index ec7cf4b879..dac8c3a62b 100644
--- a/packages/studio-server/src/preview-server/public-folder.ts
+++ b/packages/studio-server/src/preview-server/public-folder.ts
@@ -5,21 +5,17 @@ import type {StaticFile} from 'remotion';
import {envSupportsFsRecursive} from './env-supports-fs-recursive';
let files: StaticFile[] = [];
-let staticFileCacheBust: string | null = null;
export const initPublicFolderWatch = ({
- cacheBust,
publicDir,
onUpdate,
staticHash,
}: {
publicDir: string;
remotionRoot: string;
- cacheBust: string | null;
onUpdate: () => void;
staticHash: string;
}) => {
- staticFileCacheBust = cacheBust;
fetchFolder({publicDir, staticHash});
watchPublicFolder({publicDir, onUpdate, staticHash});
};
@@ -39,9 +35,6 @@ export const fetchFolder = ({
}).map((f) => {
return {
...f,
- src: staticFileCacheBust
- ? `${f.src}?v=${encodeURIComponent(staticFileCacheBust)}`
- : f.src,
name: f.name.split(path.sep).join('/'),
};
});
diff --git a/packages/studio-server/src/start-studio.ts b/packages/studio-server/src/start-studio.ts
index ea26f1ccbb..f1e77e9576 100644
--- a/packages/studio-server/src/start-studio.ts
+++ b/packages/studio-server/src/start-studio.ts
@@ -135,12 +135,7 @@ export const startStudio = async ({
.digest('hex')
.slice(0, 12)}`;
- // Previously, restarting Studio changed every asset URL, allowing users to
- // recover from replaced files or stale browser/media caches. Reuse the random
- // output namespace as a query version to preserve that behavior for newly
- // loaded Studios, while stable paths keep old asset URLs valid across restarts.
initPublicFolderWatch({
- cacheBust: outputHash,
publicDir,
remotionRoot,
onUpdate: () => {
diff --git a/packages/studio/src/api/delete-static-file.ts b/packages/studio/src/api/delete-static-file.ts
index 2dc5d40526..7c15934511 100644
--- a/packages/studio/src/api/delete-static-file.ts
+++ b/packages/studio/src/api/delete-static-file.ts
@@ -10,12 +10,9 @@ export const deleteStaticFile = async (
throw new Error('deleteStaticFile() is only available in the Studio');
}
- if (
- window.remotion_staticBase &&
- relativePath.startsWith(window.remotion_staticBase + '/')
- ) {
- relativePath = decodeURIComponent(
- relativePath.slice(window.remotion_staticBase.length + 1).split('?')[0],
+ if (relativePath.startsWith(window.remotion_staticBase)) {
+ relativePath = relativePath.substring(
+ window.remotion_staticBase.length + 1,
);
}
diff --git a/packages/studio/src/api/watch-static-file.ts b/packages/studio/src/api/watch-static-file.ts
index 4948852bf2..f90258b345 100644
--- a/packages/studio/src/api/watch-static-file.ts
+++ b/packages/studio/src/api/watch-static-file.ts
@@ -33,13 +33,9 @@ export const watchStaticFile = (
return {cancel: () => undefined};
}
- const withoutStaticBase =
- window.remotion_staticBase &&
- fileName.startsWith(window.remotion_staticBase + '/')
- ? decodeURIComponent(
- fileName.slice(window.remotion_staticBase.length).split('?')[0],
- )
- : fileName;
+ const withoutStaticBase = fileName.startsWith(window.remotion_staticBase)
+ ? fileName.replace(window.remotion_staticBase, '')
+ : fileName;
const withoutLeadingSlash = withoutStaticBase.startsWith('/')
? withoutStaticBase.slice(1)
: withoutStaticBase;
diff --git a/packages/studio/src/components/Timeline/timeline-asset-link.ts b/packages/studio/src/components/Timeline/timeline-asset-link.ts
index 43bfc6aa47..15b23db848 100644
--- a/packages/studio/src/components/Timeline/timeline-asset-link.ts
+++ b/packages/studio/src/components/Timeline/timeline-asset-link.ts
@@ -51,9 +51,7 @@ export const getTimelineAssetSrcFromSchema = (
export const getTimelineAssetLinkInfo = (src: string): LinkInfo => {
if (src.startsWith(NoReactInternals.FILE_TOKEN)) {
- const encodedAssetPath = src
- .slice(NoReactInternals.FILE_TOKEN.length)
- .split('?')[0];
+ const encodedAssetPath = src.slice(NoReactInternals.FILE_TOKEN.length);
let assetPath = encodedAssetPath;
try {
assetPath = encodedAssetPath.split('/').map(decodeURIComponent).join('/');
@@ -72,7 +70,7 @@ export const getTimelineAssetLinkInfo = (src: string): LinkInfo => {
typeof window === 'undefined' ? null : window.remotion_staticBase;
if (staticBase && src.startsWith(staticBase + '/')) {
- const assetPath = src.slice(staticBase.length + 1).split('?')[0];
+ const assetPath = src.slice(staticBase.length + 1);
return {
kind: 'local',
assetPath: decodeURIComponent(assetPath),