{"record":{"id":"1ac0097ec919afd4","repo":"remotion-dev/remotion","slug":"the-reorder-target-is-no-longer-available","errorCode":null,"errorMessage":"The reorder target is no longer available","messagePattern":"The reorder target is no longer available","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"packages/studio-codemods/src/recast-mods.ts","lineNumber":728,"sourceCode":"\t\t\t);\n\t\t}\n\t}\n\n\tconst sourceReturnStatement = getEnclosingReturnStatement(sourceItem.path);\n\tdeleteJsxElementAtPath(sourceItem.path);\n\tconst element = stripParenthesizedExtra(sourceItem.node);\n\tif (transformation.destination.type === 'root') {\n\t\tappendElementToRoot({element, returnStatement: sourceReturnStatement});\n\t} else if (transformation.destination.type === 'folder') {\n\t\tappendElementToFolder({\n\t\t\telement,\n\t\t\tfolderElement: (destinationFolder as unknown as LocatedItem).node,\n\t\t});\n\t} else {\n\t\tconst targetItem = target as unknown as LocatedItem;\n\t\tconst targetIndex = targetItem.parent.children.indexOf(targetItem.node);\n\t\tif (targetIndex === -1) {\n\t\t\tthrow new Error('The reorder target is no longer available');\n\t\t}\n\n\t\ttargetItem.parent.children.splice(\n\t\t\ttransformation.destination.type === 'before'\n\t\t\t\t? targetIndex\n\t\t\t\t: targetIndex + 1,\n\t\t\t0,\n\t\t\telement,\n\t\t);\n\t}\n\n\tchangesMade.push({description: 'Moved composition or folder'});\n\treturn {newAst: file, changesMade};\n};\n\nconst moveCompositionToFolder = ({\n\tfile,\n\ttransformation,","sourceCodeStart":710,"sourceCodeEnd":746,"githubUrl":"https://github.com/remotion-dev/remotion/blob/a6a7485a9aeb04219510fbe4874f8941486424df/packages/studio-codemods/src/recast-mods.ts#L710-L746","documentation":"After locating the reorder target, moveCompositionOrFolder removes the source element from its parent's children array and splices it before/after the target. If the target element is no longer found in its recorded parent's children array at splice time (indexOf returns -1), this error is thrown — meaning the AST changed between locating the target and performing the splice.","triggerScenarios":"The target's parent children array does not contain targetItem.node, typically because a prior transformation in the same applyCodemod batch already removed or re-parented the target element, or the same node was matched at two locations.","commonSituations":"Batched codemods where an earlier move deleted/moved the target; conflicting overlapping transformations; concurrent edits to the composition file during codemod execution.","solutions":["Re-run the codemod against a freshly parsed file so all targets are located against current state","Ensure batched transformations do not remove or move each other's targets","Apply transformations sequentially, re-reading the file between each"],"exampleFix":"// before\napplyCodemods([moveAAfterB, removeB]); // removeB invalidates moveAAfterB's target\n// after\napplyCodemods([removeB]);\napplyCodemods([regenerateAndMoveAAfterSiblingOfB]); // recompute target after B is gone","handlingStrategy":"retry","validationCode":"// after each transformation, re-parse before computing the next one\nconst ast = parse(readFileSync(compositionFile, 'utf8'));","typeGuard":null,"tryCatchPattern":"try {\n  await applyCodemod({transformation});\n} catch (e) {\n  if (String(e) === 'Error: The reorder target is no longer available') {\n    await applyCodemod({transformation: regenerateTransformation(freshParse())}); // retry with fresh state\n  } else throw e;\n}","preventionTips":["Re-parse the file between batched transformations so targets are located against current state","Avoid batching transformations that remove or move each other's targets","Serialize all writes to a composition file (single write queue) to prevent concurrent mutation"],"tags":["codemod","ast","race-condition"],"backgroundTag":"stale-ast-state","analyzedSha":"a6a7485a9aeb04219510fbe4874f8941486424df","analyzedAt":"2026-09-02T16:25:19.997Z","contentChangedAt":"2026-09-02T16:25:19.997Z","schemaVersion":2},"datasetVersion":"2026-09-14T00:17:10.932Z"}