Skip to content

Add Pace.version, run only the first copy of pace on a page - #580

Open
CodeByZach wants to merge 1 commit into
candidate-2.0from
small-properties
Open

CodeByZach wants to merge 1 commit into
candidate-2.0from
small-properties

Conversation

@CodeByZach

Copy link
Copy Markdown
Owner

Adds Pace.version, makes Pace.running read-only, removes internal properties, and runs only the first copy of pace on a page.

  • Pace.version: the package version, stamped into pace.js by the build from package.json.
  • Pace.running is read-only.
  • Removed: Pace.bar, Pace.sources and Pace.bindings, which exposed pace's internals.
  • A second copy of pace (another script tag or bundle, or one loaded after Pace 1.x) logs a warning and does nothing else; a bundled one exports the first copy. Before, a page that loaded pace twice showed two bars and tracked every request twice. The first copy is found through window[Symbol.for('pace-js')], which page markup can't replace.
  • Any other window.Pace, such as an element with id="Pace", is replaced. Before, pace added its functions to it, and a cross-origin frame named Pace stopped pace at load.

Tests cover each property and each case of a second copy; all 10 fail on the previous code.

- Pace.version is the package version. The build stamps it from
  package.json into pace.js, as it already does for the header, so CI's
  check that the build is up to date also catches a mismatch.
- Pace.running is read-only: an accessor, so assigning to it does
  nothing (or throws in strict-mode code) instead of changing what pace
  reports.
- Pace.bar, Pace.sources and Pace.bindings are removed: they exposed
  pace's internals. The event handlers live in pace's closure.
- A second copy of pace on a page (another script tag or bundle) logs a
  warning and does nothing else; a bundled one exports the first copy.
  Before, it merged into window.Pace and wrapped XMLHttpRequest, fetch
  and history again, so the page showed two bars. The first copy is
  found through window[Symbol.for('pace-js')], which page markup can't
  replace (element names are strings), or, for Pace 1.x, which doesn't
  set it, a window.Pace with a start function. A copy registers itself
  only once it's complete. zone.js and Sentry also let the first copy
  win; Datadog and Lit warn about a second one.
- Any other window.Pace, such as an element with id="Pace", is replaced.
  Before, pace added its functions to it, and a cross-origin frame named
  Pace stopped pace at load.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant