Skip to content

🎥 Make videos programmatically with React

make resolveGifSource helper

Jonny Burger73e11bcda0af
diff --git a/packages/gif/src/GifForDevelopment.tsx b/packages/gif/src/GifForDevelopment.tsx
index ba4a84203b..129065ee5c 100644
--- a/packages/gif/src/GifForDevelopment.tsx
+++ b/packages/gif/src/GifForDevelopment.tsx
@@ -5,6 +5,7 @@ import {gifCache} from './gif-cache';
import {isCorsError} from './is-cors-error';
import type {GifState, RemotionGifProps} from './props';
import {parseWithWorker} from './react-tools';
+import {resolveGifSource} from './resolve-gif-source';
import {useCurrentGifIndex} from './useCurrentGifIndex';
export const GifForDevelopment = forwardRef<
@@ -24,10 +25,7 @@ export const GifForDevelopment = forwardRef<
},
ref
) => {
- const resolvedSrc = new URL(
- src,
- typeof window === 'undefined' ? undefined : window.location.origin
- ).href;
+ const resolvedSrc = resolveGifSource(src);
const [state, update] = useState<GifState>(() => {
const parsedGif = gifCache.get(resolvedSrc);
diff --git a/packages/gif/src/GifForRendering.tsx b/packages/gif/src/GifForRendering.tsx
index bfd9cb6e5e..0dc402f83a 100644
--- a/packages/gif/src/GifForRendering.tsx
+++ b/packages/gif/src/GifForRendering.tsx
@@ -5,6 +5,7 @@ import {gifCache} from './gif-cache';
import {isCorsError} from './is-cors-error';
import type {GifState, RemotionGifProps} from './props';
import {parseGif} from './react-tools';
+import {resolveGifSource} from './resolve-gif-source';
import {useCurrentGifIndex} from './useCurrentGifIndex';
export const GifForRendering = forwardRef<HTMLCanvasElement, RemotionGifProps>(
@@ -21,7 +22,7 @@ export const GifForRendering = forwardRef<HTMLCanvasElement, RemotionGifProps>(
},
ref
) => {
- const resolvedSrc = new URL(src, window.location.origin).href;
+ const resolvedSrc = resolveGifSource(src);
const [state, update] = useState<GifState>(() => {
const parsedGif = gifCache.get(resolvedSrc);
diff --git a/packages/gif/src/resolve-gif-source.ts b/packages/gif/src/resolve-gif-source.ts
new file mode 100644
index 0000000000..3dc0ad2850
--- /dev/null
+++ b/packages/gif/src/resolve-gif-source.ts
@@ -0,0 +1,6 @@
+export const resolveGifSource = (src: string): string => {
+ return new URL(
+ src,
+ typeof window === 'undefined' ? undefined : window.location.origin
+ ).href;
+};