{"record":{"id":"4d2fc4c8a4abd29e","repo":"remotion-dev/remotion","slug":"a-duration-of-a-spring-is-nan-which-it-must-not","errorCode":null,"errorMessage":"A \"duration\" of a spring is NaN, which it must not be","messagePattern":"A \"duration\" of a spring is NaN, which it must not be","errorType":"validation","errorClass":"TypeError","httpStatus":null,"severity":"error","filePath":"packages/core/src/validation/validation-spring-duration.ts","lineNumber":13,"sourceCode":"export const validateSpringDuration = (dur: unknown) => {\n\tif (typeof dur === 'undefined') {\n\t\treturn;\n\t}\n\n\tif (typeof dur !== 'number') {\n\t\tthrow new TypeError(\n\t\t\t`A \"duration\" of a spring must be a \"number\" but is \"${typeof dur}\"`,\n\t\t);\n\t}\n\n\tif (Number.isNaN(dur)) {\n\t\tthrow new TypeError(\n\t\t\t'A \"duration\" of a spring is NaN, which it must not be',\n\t\t);\n\t}\n\n\tif (!Number.isFinite(dur)) {\n\t\tthrow new TypeError(\n\t\t\t'A \"duration\" of a spring must be finite, but is ' + dur,\n\t\t);\n\t}\n\n\tif (dur <= 0) {\n\t\tthrow new TypeError(\n\t\t\t'A \"duration\" of a spring must be positive, but is ' + dur,\n\t\t);\n\t}\n};\n","sourceCodeStart":1,"sourceCodeEnd":30,"githubUrl":"https://github.com/remotion-dev/remotion/blob/78fe4bb3fdb5a2cd68724393d63cb223db333fa7/packages/core/src/validation/validation-spring-duration.ts#L1-L30","documentation":"`validateSpringDuration()` rejects `NaN` for the optional `duration` of a spring because a NaN duration produces NaN outputs for every frame and silently breaks the animation. It throws a `TypeError` with a precise description.","triggerScenarios":"Passing `duration: NaN` to `spring()`, typically the result of `Number(undefined)`, `parseInt(undefined)`, or `0/0`.","commonSituations":"Destructuring `duration` from an optional prop that is not always provided and feeding it straight into `spring()` without an existence check.","solutions":["Validate before calling: `if (duration != null && Number.isNaN(Number(duration))) return;`.","Default undefined values: `duration: duration ?? undefined` (the validator skips undefined).","Trace the upstream source of the NaN and fix the arithmetic."],"exampleFix":"// before\nspring({frame, fps, config, duration: Number(props.dur)}); // NaN when undefined\n// after\nspring({frame, fps, config, duration: props.dur == null ? undefined : Number(props.dur)});","handlingStrategy":"validation","validationCode":"const duration = rawDuration == null ? undefined : Number(rawDuration);\nif (duration != null && Number.isNaN(duration)) return;","typeGuard":"const isValidSpringDuration = (v: unknown): v is number | undefined => v == null || (typeof v === 'number' && !Number.isNaN(v));","tryCatchPattern":null,"preventionTips":["Always null-check optional durations before coercion.","Default missing props to `undefined`, not 0 or NaN.","Log the resolved duration value before passing to `spring()`."],"tags":["validation","spring","animation","nan","numeric"],"backgroundTag":null,"analyzedSha":"78fe4bb3fdb5a2cd68724393d63cb223db333fa7","analyzedAt":"2026-08-12T17:18:50.444Z","schemaVersion":2},"datasetVersion":"2026-08-12T18:17:37.767Z"}