{"record":{"id":"acbef284ad22a699","repo":"remotion-dev/remotion","slug":"muted-attribute-edit-is-outside-the-video-element","errorCode":null,"errorMessage":"Muted attribute edit is outside the video element","messagePattern":"Muted attribute edit is outside the video element","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"packages/studio-codemods/src/split-video-from-audio.ts","lineNumber":248,"sourceCode":"};\n\nconst applyEditToElementSource = ({\n\tedit,\n\telement,\n\tinput,\n}: {\n\tedit: SourceEdit;\n\telement: JSXElement;\n\tinput: string;\n}) => {\n\tif (!element.loc) {\n\t\tthrow new Error('Could not locate the video element');\n\t}\n\n\tconst start = recastLocToOffset(input, element.loc.start);\n\tconst end = recastLocToOffset(input, element.loc.end);\n\tif (edit.start < start || edit.end > end) {\n\t\tthrow new Error('Muted attribute edit is outside the video element');\n\t}\n\n\tconst source =\n\t\tinput.slice(start, edit.start) +\n\t\tedit.replacement +\n\t\tinput.slice(edit.end, end);\n\tconst originalIndent = getLineIndent({input, offset: start});\n\treturn source\n\t\t.split(/\\r?\\n/)\n\t\t.map((line, index) => {\n\t\t\tif (index === 0) {\n\t\t\t\treturn line;\n\t\t\t}\n\n\t\t\treturn line.startsWith(originalIndent)\n\t\t\t\t? line.slice(originalIndent.length)\n\t\t\t\t: line.trimStart();\n\t\t})","sourceCodeStart":230,"sourceCodeEnd":266,"githubUrl":"https://github.com/remotion-dev/remotion/blob/46a3a6bf13ca367376ff18bbb06dae2e87e0d068/packages/studio-codemods/src/split-video-from-audio.ts#L230-L266","documentation":"Thrown by applyEditToElementSource when the computed muted-attribute SourceEdit lies outside the byte range of the video JSXElement in the source (edit.start < element start or edit.end > element end). This is an internal consistency check: the edit being applied belongs to a different element or stale offsets. It protects against corrupting surrounding code with a misplaced splice.","triggerScenarios":"The SourceEdit computed for the muted attribute has offsets that don't fall within the video element's [start, end) range — e.g. the edit was derived from a different AST node, a stale element after the AST was mutated, or an offset mapping bug after source transformations.","commonSituations":"Chained codemod runs where the first mutation invalidates captured offsets, applying edits captured against one parse to a re-parsed source, or UI actions racing with file edits so the input string changed between parse and edit application.","solutions":["Re-parse the source and recompute the muted-attribute edit before applying it","Ensure all edits in a run are captured from the same AST parse of the same input string","Apply edits in a single batch (applySourceEdits) rather than reusing edits across mutations","Report a Remotion bug with the file and action that triggered it"],"exampleFix":"// before (stale edit applied to re-parsed input)\nconst ast2 = parseAst(newInput);\napplyEditToElementSource({edit: staleEdit, element: findElement(ast2), input: newInput});\n// after (recompute edit against the same parse)\nconst ast2 = parseAst(newInput);\nconst el = findElement(ast2);\nconst freshEdit = getMutedAttributeEdit({element: el, input: newInput});\napplyEditToElementSource({edit: freshEdit, element: el, input: newInput});","handlingStrategy":"try-catch","validationCode":"const within = (edit: SourceEdit, el: JSXElement, input: string) => {\n  if (!el.loc) return false;\n  const start = recastLocToOffset(input, el.loc.start);\n  const end = recastLocToOffset(input, el.loc.end);\n  return edit.start >= start && edit.end <= end;\n};","typeGuard":null,"tryCatchPattern":"try {\n  const source = applyEditToElementSource({edit, element, input});\n} catch (e) {\n  if (e instanceof Error && e.message.includes('outside the video element')) {\n    // recompute the muted edit against a fresh parse of the same input\n    const fresh = computeMutedEdit(parseAst(input), input);\n    return applyEditToElementSource({edit: fresh, element, input});\n  }\n  throw e;\n}","preventionTips":["Capture all SourceEdits from one parse of the same input string","Never reuse offsets after AST or source mutations — recompute them","Apply batched edits via applySourceEdits instead of applying stale edits individually"],"tags":["codemod","source-edit","offset-mismatch"],"backgroundTag":"edit-out-of-range","analyzedSha":"46a3a6bf13ca367376ff18bbb06dae2e87e0d068","analyzedAt":"2026-09-18T00:12:20.256Z","contentChangedAt":"2026-09-18T00:12:20.256Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}