Superpositions of rotational states in polar molecules induce strong, long-range dipolar interactions. Here we extend the rotational coherence by nearly one order of magnitude to 8.7(6) ms in a dilute gas of polar $^{23}$Na$^{40}$K molecules in an optical trap. We demonstrate spin-decoupled magic trapping, which cancels first-order and reduces second-order differential light shifts. The latter is achieved with a dc electric field that decouples nuclear spin, rotation and trapping light field. We observe density-dependent coherence times, which can be explained by dipolar interactions in the bulk gas.