Skip to content

Keep only comments a reader needs in pace.js - #581

Open
CodeByZach wants to merge 1 commit into
small-propertiesfrom
trim-comments
Open

CodeByZach wants to merge 1 commit into
small-propertiesfrom
trim-comments

Conversation

@CodeByZach

Copy link
Copy Markdown
Owner

Comments in pace.js now say what code does where it isn't obvious, what would break if it changed, and their sources. The reasons behind earlier choices move into the commit message.

Only comments change: pace.min.js builds byte-for-byte the same.

Comments now say what code does where it isn't obvious, what would
break if it changed, and their sources. The reasons behind choices move
here, where they belong:

- Pace keeps the first copy's object under Symbol.for('pace-js') because
  page markup can't replace a symbol property (element names are
  strings); a later copy would otherwise wrap requests and history again
  and add a second bar.
- RegExps in settings are copied because a RegExp's lastIndex changes as
  it's used and the page could freeze it.
- reportError keeps an error's details for window.onerror even when
  pace.js is served from another origin.
- A request sent just before a run starts belongs to that run: Turbolinks
  sends one, then calls pushState.
- maxWait exists so a request that never ends can't hold the bar forever.
- WebSocket is replaced by a subclass so instanceof, its constants,
  subclasses and other libraries' prototype patches keep working.
- waitFor checks every 100 ms because no event says when a selector
  starts to match, and a MutationObserver misses matches that come from
  state, such as :checked or :defined.
- The document monitor uses addEventListener, not
  document.onreadystatechange, so a page that sets that property doesn't
  disconnect pace.
- Errors from extra sources are reported only once the run is set up,
  because an error listener may call Pace.start().
- The fetch wrapper's checks never throw because fetch itself rejects
  input it can't use, such as a URL whose toString() throws.
- es-abstract's IsConstructor uses the same Reflect.construct check;
  the comment now credits it.

Only comments change: pace.min.js builds byte-for-byte the same.

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