chore(HMR clients): Clean up and share code between app and pages router (#76960)
# Do not review this PR in Graphite, review it one commit at a time: https://github.com/vercel/next.js/pull/76960/commits
This is a series of very small changes to the hot reloader clients in both app and pages router to share more code and unify some of the logic or behavior between the two.
This code is very fragile, so lots of small commits have been useful in bisecting test failures.
These changes are too small to be practical as separate stacked graphite PRs.