Repository navigation
Add Pace.version, run only the first copy of pace on a page - #580
Open
CodeByZach wants to merge 2 commits into
Open
CodeByZach wants to merge 2 commits into
CodeByZach wants to merge 2 commits into
Conversation
- 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.
- An extra source that throws while pace constructs it is reported like an uncaught error (reportError), and the run goes on without it. The errors are reported once the run is set up, so an error listener that calls Pace.start() doesn't start a second run. Before, Pace.start() threw, and if a run was finishing, Pace.running stayed true and <body> kept pace-running for good. This also covers values that pass the constructor check but still throw, such as Symbol. - The bar is added once <body> exists, and Pace.stop() works before it does. A target that exists before <body>, such as 'html' with pace in <head>, threw at load and left Pace.running true; history.pushState called from <head> after pace made the restart throw, so the page never showed the bar. - README: pace.min.js is about 5.7 kB gzipped; it said about 4 kB, which stopped being true as the file grew. The smallest theme is 0.3 kB, not 0.2. Pace.getOptions() returns the current settings; a bar that is showing keeps the non-request settings it started with. progress fires up to about 30 times a second, and restart also fires on pushState and replaceState. - The warnings for the version 1 eventLag and elements settings also say that their tuning settings and checkInterval were removed. Corrects earlier commit messages: - f46eecd: a frozen RegExp with the g flag made send() throw inside RegExp.prototype.test, which writes lastIndex; pace's own reset of lastIndex did nothing. A <form id="paceOptions"> stopped the bar only when it had a control named after a setting, such as target. - 6bddc5e: in Sentry, the first copy sets the shared version, but each version keeps its own state. Datadog's second copy warns, then replaces the global. Lit warns only in development builds. - 6a2c31b: a library that patched XMLHttpRequest.prototype after pace patched the plain prototype object of pace's wrapper function, so it never saw a request. WebSocket is still replaced, by a subclass, so instanceof, its constants and prototype patches keep working. Reopening a request, and sending it again from its own load handler, already worked before that commit. - b17e3c0, and the matching code comment: setTimeout treats Infinity as 0 but wraps larger numbers around 2^32 (2^32 + 300 ms fires after about 300 ms), so only 0 to 2^31 - 1 means the delay given.
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Adds
Pace.version, makesPace.runningread-only, removes internal properties, and runs only the first copy of pace on a page.Pace.version: the package version, stamped intopace.jsby the build frompackage.json.Pace.runningis read-only.Pace.bar,Pace.sourcesandPace.bindings, which exposed pace's internals.window[Symbol.for('pace-js')], which page markup can't replace.window.Pace, such as an element withid="Pace", is replaced. Before, pace added its functions to it, and a cross-origin frame namedPacestopped pace at load.Tests cover each property and each case of a second copy; all 10 fail on the previous code.