server-app: make _sortLayersByPhase stable

Fix the phase-sorting algorithm to use a stable sorting algorithm,
since the built-in `Array.prototype.sort` is not stable.

/to @ritch or @raymondfeng please review