🎥 Make videos programmatically with React
Remotion Studio: Fix static site deploys not respecting pathnames
Jonny Burgerce4f8930f7df
diff --git a/packages/studio/src/components/InitialCompositionLoader.tsx b/packages/studio/src/components/InitialCompositionLoader.tsxindex 821d2e2b05..8ce2de55ad 100644--- a/packages/studio/src/components/InitialCompositionLoader.tsx+++ b/packages/studio/src/components/InitialCompositionLoader.tsx@@ -3,7 +3,7 @@ import {useContext, useEffect} from 'react';import type {AnyComposition} from 'remotion';import {getStaticFiles, Internals} from 'remotion';import type {ExpandedFoldersState} from '../helpers/persist-open-folders';-import {getPathname, pushUrl} from '../helpers/url-state';+import {getRoute, pushUrl} from '../helpers/url-state';import {FolderContext} from '../state/folders';import {getKeysToExpand} from './CompositionSelector';import {explorerSidebarTabs} from './ExplorerPanel';@@ -114,7 +114,7 @@ export const InitialCompositionLoader: React.FC = () => {const onchange = () => {const newCanvas = deriveCanvasContentFromUrl();if (newCanvas && newCanvas.type === 'composition') {- const newComp = getPathname().substring(1);+ const newComp = getRoute().substring(1);const exists = compositions.find((c) => c.id === newComp);if (exists) {selectComposition(exists, false);diff --git a/packages/studio/src/components/ZoomPersistor.tsx b/packages/studio/src/components/ZoomPersistor.tsxindex bfeee58dd5..e424b71009 100644--- a/packages/studio/src/components/ZoomPersistor.tsx+++ b/packages/studio/src/components/ZoomPersistor.tsx@@ -2,7 +2,7 @@ import type React from 'react';import {useContext, useEffect} from 'react';import type {CanvasContent} from 'remotion';import {Internals} from 'remotion';-import {getPathname} from '../helpers/url-state';+import {getRoute} from '../helpers/url-state';import {TimelineZoomCtx} from '../state/timeline-zoom';const makeKey = () => {@@ -19,21 +19,21 @@ export const getZoomFromLocalStorage = (): Record<string, number> => {};export const deriveCanvasContentFromUrl = (): CanvasContent | null => {- const substrings = getPathname().split('/').filter(Boolean);+ const substrings = getRoute().split('/').filter(Boolean);const lastPart = substrings[substrings.length - 1];if (substrings[0] === 'assets') {return {type: 'asset',- asset: decodeURIComponent(getPathname().substring('/assets/'.length)),+ asset: decodeURIComponent(getRoute().substring('/assets/'.length)),};}if (substrings[0] === 'outputs') {return {type: 'output',- path: decodeURIComponent(getPathname().substring('/outputs/'.length)),+ path: decodeURIComponent(getRoute().substring('/outputs/'.length)),};}diff --git a/packages/studio/src/helpers/url-state.ts b/packages/studio/src/helpers/url-state.tsindex e372b4521c..3f89e33a80 100644--- a/packages/studio/src/helpers/url-state.ts+++ b/packages/studio/src/helpers/url-state.ts@@ -10,21 +10,25 @@ const getUrlHandlingType = (): UrlHandling => {export const pushUrl = (url: string) => {if (getUrlHandlingType() === 'query-string') {- window.history.pushState({}, 'Studio', `/?${url}`);+ window.history.pushState(+ {},+ 'Studio',+ `${window.location.pathname}?${url}`,+ );} else {window.history.pushState({}, 'Studio', url);}};export const clearUrl = () => {- window.location.href = '/';+ window.location.href = window.location.pathname;};export const reloadUrl = () => {window.location.reload();};-export const getPathname = () => {+export const getRoute = () => {if (getUrlHandlingType() === 'query-string') {return window.location.search.substring(1);}