Skip to content

Commit

Permalink
url: more comments to explain lazy searchParams updating
Browse files Browse the repository at this point in the history
  • Loading branch information
MattIPv4 committed Jan 19, 2024
1 parent 916374e commit 319eaa0
Showing 1 changed file with 5 additions and 3 deletions.
8 changes: 5 additions & 3 deletions lib/internal/url.js
Original file line number Diff line number Diff line change
Expand Up @@ -776,10 +776,11 @@ class URL {

static {
setURLSearchParamsModified = (obj) => {
// If URLSearchParams gets updated, use that as the source-of-truth for search.
// When URLSearchParams changes, we lazily update URL on the next read/write for performance.
obj.#searchParamsModified = true;

// If URL has an existing search, remove it without cascading back to URLSearchParams
// If URL has an existing search, remove it without cascading back to URLSearchParams.
// Do this to avoid any internal confusion about whether URLSearchParams or URL is up-to-date.
if (obj.#context.hasSearch) {
obj.#updateContext(bindingUrl.update(obj.#context.href, updateActions.kSearch, ''), false);
}
Expand Down Expand Up @@ -845,7 +846,8 @@ class URL {
}

#checkSearchParams() {
// If URLSearchParams has been modified, reflect that back into URL.
// If URLSearchParams has been modified, reflect that back into URL, and do not cascade back.
// This is done lazily to greatly improve performance when URLSearchParams is updated repeatedly.
if (this.#searchParamsModified) {
const href = bindingUrl.update(this.#context.href, updateActions.kSearch, this.#getSearchFromParams());
this.#updateContext(href, false);
Expand Down

0 comments on commit 319eaa0

Please sign in to comment.