Skip to content

🎥 Make videos programmatically with React

make new cache on every commit

Jonny Burger546cbd510df6
diff --git a/packages/convert/app/entry.client.tsx b/packages/convert/app/entry.client.tsx
index fca0a8ff17..6da13ef195 100644
--- a/packages/convert/app/entry.client.tsx
+++ b/packages/convert/app/entry.client.tsx
@@ -9,6 +9,12 @@ const registerServiceWorker = () => {
.register('/convert/service-worker.js', {
scope: '/convert', // "/convert", not "/convert/"
})
+ .then((registration) => {
+ console.log(
+ 'Service worker registered, site is now available offline',
+ );
+ registration.update();
+ })
.catch((error) => {
console.log('SW registration failed:', error);
});
diff --git a/packages/convert/app/service-worker.ts b/packages/convert/app/service-worker.ts
index c922339f1b..3139d9d6d4 100644
--- a/packages/convert/app/service-worker.ts
+++ b/packages/convert/app/service-worker.ts
@@ -4,7 +4,8 @@ const $FILES = [];
// ^ leave this - will get filled in during build
// --auto-generated-until-here
-const CACHE_NAME = 'remotion-convert-v1';
+const CACHE_NAME = 'ABCDEF';
+// ^ leave this - will get filled in during build
// Helper function to determine if a request is under /convert
function isConvertPath(url) {
diff --git a/packages/convert/build-service-worker.ts b/packages/convert/build-service-worker.ts
index e3915effe2..44264c7452 100644
--- a/packages/convert/build-service-worker.ts
+++ b/packages/convert/build-service-worker.ts
@@ -32,12 +32,25 @@ if (!firstOutput) {
throw new Error('No output');
}
const text = await firstOutput.text();
+
const replaced = '$FILES = [];';
if (!text.includes(replaced)) {
throw new Error('Unexpected output');
}
+const cacheNameReplacer = 'CACHE_NAME = "ABCDEF"';
+
+if (!text.includes(cacheNameReplacer)) {
+ throw new Error('Unexpected output');
+}
+
+const gitRef =
+ // eslint-disable-next-line @remotion/deterministic-randomness
+ process.env.VERCEL_GIT_COMMIT_SHA || Math.random().toString(36).slice(2);
+
await Bun.write(
'spa-dist/client/service-worker.js',
- text.replace(replaced, `$FILES = ${JSON.stringify(toCache)};`),
+ text
+ .replace(replaced, `$FILES = ${JSON.stringify(toCache)};`)
+ .replace(cacheNameReplacer, `CACHE_NAME = 'convert-${gitRef}'`),
);