This only occurs if the player character does the replacement; if a construction bot does it, the connections are maintained through the undo (which seems like the intended behavior). This happens when undoing after replacing an item with one of a different tier, with one of a different quality, or with the same item in a different rotation. The rotation one also issues an extra construction bot job when undoing, which isn't done if you overwrite the rotation via the map view or ghost planner before undoing.
Red and green circuit wires are disconnected, and so are wires between power poles
From my testing, this happened with:
- Inserters, belts, power poles, and chests of different tiers
- Chests of different rarities
- Belts and inserters with different orientations