{"record":{"id":"532a4bcf5e9e0d0b","repo":"remotion-dev/remotion","slug":"restartstudio-is-only-available-in-the-studio","errorCode":null,"errorMessage":"restartStudio() is only available in the Studio","messagePattern":"restartStudio\\(\\) is only available in the Studio","errorType":"validation","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"packages/studio/src/api/restart-studio.ts","lineNumber":13,"sourceCode":"/**\n * @description Restarts the Remotion Studio.\n * @see [Documentation](https://www.remotion.dev/docs/studio/restart-studio)\n */\n\nimport type {RestartStudioResponse} from '@remotion/studio-shared';\nimport {getRemotionEnvironment} from 'remotion';\nimport {callApi} from '../components/call-api';\nimport {getBrowserStudioOperations} from '../helpers/browser-studio-operations';\n\nexport const restartStudio = (): Promise<RestartStudioResponse> => {\n\tif (!getRemotionEnvironment().isStudio) {\n\t\tthrow new Error('restartStudio() is only available in the Studio');\n\t}\n\n\tif (getBrowserStudioOperations() !== null) {\n\t\tthrow new Error('restartStudio() is not supported in Browser Studio');\n\t}\n\n\tif (window.remotion_isReadOnlyStudio) {\n\t\tthrow new Error('restartStudio() is not available in read-only Studio');\n\t}\n\n\treturn callApi('/api/restart-studio', {});\n};\n","sourceCodeStart":1,"sourceCodeEnd":26,"githubUrl":"https://github.com/remotion-dev/remotion/blob/10db9de07356446fb0edb3c3ae211369b693d18b/packages/studio/src/api/restart-studio.ts#L1-L26","documentation":"restartStudio() restarts the Studio server via /api/restart-studio and only exists inside the Node-based Studio. The first guard requires getRemotionEnvironment().isStudio to be true; outside Studio (renders, the Player, plain React/Node apps) it throws immediately. Sibling guards also reject Browser Studio and read-only Studio.","triggerScenarios":"Calling restartStudio() from code that also runs outside Studio - compositions, shared hooks, Node scripts - or from an embedded Player preview; e.g. an 'update and restart' button defined in a module imported by both Studio UI and render-time code.","commonSituations":"Update flows written in shared utility modules that execute in both Studio and non-Studio environments; code copied from Studio internals into a Player app.","solutions":["Restrict restartStudio() to Studio-only UI (toolbar buttons rendered only within Studio).","Guard with getRemotionEnvironment().isStudio before calling.","Handle the sibling cases too: in Browser Studio and read-only Studio the call throws separate errors - skip or hide the restart action there.","If you need a restart-like experience outside Studio, restart your own dev server process instead."],"exampleFix":"// before\nimport {restartStudio} from '@remotion/studio';\n\nexport const onUpdate = () => restartStudio(); // throws outside Studio\n\n// after\nimport {getRemotionEnvironment} from 'remotion';\nimport {restartStudio} from '@remotion/studio';\n\nexport const onUpdate = () => {\n  if (!getRemotionEnvironment().isStudio) {\n    return; // no-op outside Studio\n  }\n  return restartStudio();\n};","handlingStrategy":"type-guard","validationCode":"import {getRemotionEnvironment} from 'remotion';\n\nif (!getRemotionEnvironment().isStudio) {\n  // do not call restartStudio() here - it throws outside Studio\n} else {\n  await restartStudio();\n}","typeGuard":"import {getRemotionEnvironment} from 'remotion';\n\nexport const canRestartStudio = (): boolean =>\n  getRemotionEnvironment().isStudio;","tryCatchPattern":"try {\n  await restartStudio();\n} catch (err) {\n  if (err.message.includes('only available in the Studio')) {\n    // called outside Studio - no-op, there is no Studio server to restart\n  } else {\n    throw err;\n  }\n}","preventionTips":["Only call restartStudio() from Studio-only UI (toolbars, menus rendered inside Studio).","Guard with getRemotionEnvironment().isStudio; also handle the separate Browser Studio and read-only Studio errors if those modes apply to you.","Put Studio-only integrations in dedicated modules so render-time code never imports them."],"tags":["studio","api-misuse","environment-check","restart"],"backgroundTag":"studio-only-api","analyzedSha":"10db9de07356446fb0edb3c3ae211369b693d18b","analyzedAt":"2026-08-22T21:45:17.748Z","contentChangedAt":"2026-08-22T21:45:17.748Z","schemaVersion":2},"datasetVersion":"2026-09-14T05:17:10.506Z"}