remotion-dev/remotion · error · Error

Overlapping source edit ranges

Error message

Overlapping source edit ranges

What it means

applySourceEdits applies a list of text replacements to a source string, sorting them from last to first so earlier offsets stay valid. Before applying each edit it verifies the edit's range does not overlap the previously applied (later-in-file) edit; if edit.end extends past the previous edit's start, the ranges conflict and the library throws instead of producing silently corrupted output.

Solutions

  1. Audit your edits for overlap: sort by start and assert each edit's end <= the next edit's start before calling applySourceEdits.
  2. Collapse overlapping edits into one larger edit covering both changes.
  3. Recompute all edits from a single, current parse of the input so offsets agree.
  4. Catch the error, log the offending edit list, and re-run the transform producing fewer/coarser edits.

Example fix

// before: overlapping edits
edits.push({start: 10, end: 30, replacement: 'a'}, {start: 20, end: 25, replacement: 'b'});
// after: merge into one non-overlapping edit
edits.push({start: 10, end: 30, replacement: 'a + b merge'});
Defensive patterns

Strategy: validation

Validate before calling

const sorted = edits.slice().sort((a, b) => a.start - b.start);
for (let i = 1; i < sorted.length; i++) {
  if (sorted[i].start < sorted[i - 1].end) {
    throw new Error(`Edits overlap at ${sorted[i].start}..${sorted[i].end}`);
  }
}

Try / catch

try {
  const output = applySourceEdits({input, edits});
} catch (err) {
  if ((err as Error).message.includes('Overlapping')) {
    // merge or recompute edits from a single parse
  }
}

Prevention

When it happens

Trigger: Building a SourceEdit array where two edits share or overlap byte ranges — e.g. replacing an attribute's value while also replacing the entire element containing it, inserting text inside a range another edit replaces, or computing offsets from a stale version of the input after manual string manipulation.

Common situations: Composing multiple codemods' edits into one batch without deduplication; off-by-one range errors in custom edits; edits computed against different parse snapshots of the same file.

Understand the failure class

Background: "Must be a positive integer", "Invalid value", "Unsupported": the invalid-argument-value error family, when a library rejects the value you pass — this error's family across 35 libraries.

Related errors


AI-assisted analysis of remotion-dev/remotion@46a3a6bf13 (2026-09-18). Data as JSON: /api/errors/6ec5e922a63eecd9. Report an issue: GitHub.

Appendix: source

Thrown at packages/studio-codemods/src/source-edits.ts:554

		}
	}

	return edits;
};

export const applySourceEdits = ({
	edits,
	input,
}: {
	edits: SourceEdit[];
	input: string;
}) => {
	const sorted = edits.slice().sort((left, right) => right.start - left.start);
	let output = input;
	let previousStart = input.length + 1;
	for (const edit of sorted) {
		if (edit.end > previousStart) {
			throw new Error('Overlapping source edit ranges');
		}

		output =
			output.slice(0, edit.start) + edit.replacement + output.slice(edit.end);
		previousStart = edit.start;
	}

	return output;
};

View on GitHub (pinned to 46a3a6bf13)