{"record":{"id":"9dc4e376e2b96698","repo":"remotion-dev/remotion","slug":"usecurrentscale-was-called-outside-of-a-remotion","errorCode":null,"errorMessage":"useCurrentScale() was called outside of a Remotion context.\nThis hook can only be called in a component that is being rendered by Remotion.\nIf you want to this hook to return 1 outside of Remotion, pass {dontThrowIfOutsideOfRemotion: true} as an option.\nIf you think you called this hook in a Remotion component, make sure all versions of Remotion are aligned.","messagePattern":"useCurrentScale\\(\\) was called outside of a Remotion context\\.\nThis hook can only be called in a component that is being rendered by Remotion\\.\nIf you want to this hook to return 1 outside of Remotion, pass (.+?) as an option\\.\nIf you think you called this hook in a Remotion component, make sure all versions of Remotion are aligned\\.","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"packages/core/src/use-current-scale.ts","lineNumber":121,"sourceCode":"\t);\n\n\tReact.useEffect(() => {\n\t\tconst update = () => setPortalScale(getPortalNodeCurrentScale());\n\t\tupdate();\n\n\t\treturn subscribeToPortalNodeCurrentScale(update);\n\t}, []);\n\n\tif (hasContext === null || config === null || zoomContext === null) {\n\t\tif (options?.dontThrowIfOutsideOfRemotion) {\n\t\t\treturn 1;\n\t\t}\n\n\t\tif (env.isRendering) {\n\t\t\treturn 1;\n\t\t}\n\n\t\tthrow new Error(\n\t\t\t[\n\t\t\t\t'useCurrentScale() was called outside of a Remotion context.',\n\t\t\t\t'This hook can only be called in a component that is being rendered by Remotion.',\n\t\t\t\t'If you want to this hook to return 1 outside of Remotion, pass {dontThrowIfOutsideOfRemotion: true} as an option.',\n\t\t\t\t'If you think you called this hook in a Remotion component, make sure all versions of Remotion are aligned.',\n\t\t\t].join('\\n'),\n\t\t);\n\t}\n\n\tif (hasContext.type === 'scale') {\n\t\treturn hasContext.scale;\n\t}\n\n\t// Studio initially renders the composition into an unscaled offscreen portal.\n\t// Return the scale that the preview has actually committed to that portal.\n\treturn portalScale;\n};\n","sourceCodeStart":103,"sourceCodeEnd":139,"githubUrl":"https://github.com/remotion-dev/remotion/blob/78fe4bb3fdb5a2cd68724393d63cb223db333fa7/packages/core/src/use-current-scale.ts#L103-L139","documentation":"useCurrentScale() reads CurrentScaleContext, PreviewSizeContext, and the video config. If any of those is missing the hook is outside a Remotion render. It throws unless you opted out via `{dontThrowIfOutsideOfRemotion: true}` or are inside an actual render pass (where it returns 1). The message also flags a possible version mismatch.","triggerScenarios":"Calling useCurrentScale() in a component rendered outside <Player>/Studio, or calling it during SSR without the opt-out option, or when duplicate @remotion installs give different React context object identities.","commonSituations":"Sharing a scaling-aware component with a non-Remotion React app; rendering such a component in a unit test without a Player wrapper; bundler-resolved duplicate @remotion/core copies.","solutions":["Call useCurrentScale() only inside components rendered by <Player> or a <Composition>.","If you intentionally call it outside Remotion, pass `{dontThrowIfOutsideOfRemotion: true}` to get 1 back.","Run `npx remotion versions` and dedupe so all @remotion/* packages resolve to one install."],"exampleFix":"// before\nconst scale = useCurrentScale();\n\n// after (outside Remotion)\nconst scale = useCurrentScale({dontThrowIfOutsideOfRemotion: true});","handlingStrategy":"fallback","validationCode":"// If you must call it outside Remotion, opt out of the throw\nconst scale = useCurrentScale({dontThrowIfOutsideOfRemotion: true});","typeGuard":null,"tryCatchPattern":"let scale = 1;\ntry {\n  scale = useCurrentScale();\n} catch (e) {\n  if (/useCurrentScale/.test((e as Error).message)) scale = 1;\n  else throw e;\n}","preventionTips":["Pass {dontThrowIfOutsideOfRemotion: true} when calling useCurrentScale() in shared components.","Keep scaling-aware logic inside <Player>/<Composition> trees where possible.","Dedupe @remotion/* so React context identity is stable."],"tags":["react","context","hook","scale","player","version-mismatch"],"backgroundTag":null,"analyzedSha":"78fe4bb3fdb5a2cd68724393d63cb223db333fa7","analyzedAt":"2026-08-12T17:18:50.444Z","schemaVersion":2},"datasetVersion":"2026-08-12T23:17:12.415Z"}