Skip to content

Commit

Permalink
hmm
Browse files Browse the repository at this point in the history
  • Loading branch information
NullVoxPopuli committed Jan 16, 2025
1 parent 252d3c7 commit 9af42ec
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 25 deletions.
56 changes: 32 additions & 24 deletions apps/repl/app/utils/editor-text.ts
Original file line number Diff line number Diff line change
Expand Up @@ -161,10 +161,11 @@ export class FileURIComponent {
#frame?: number;
#qps: URLSearchParams | undefined;
#updateQPs = async (rawText: string, format: Format) => {
await waitForPromise(this.#_updateQPs(rawText, format));
waitForPromise(this.#_updateQPs(rawText, format));
};

#_updateQPs = async (rawText: string, format: Format) => {
console.debug('queueing QPs');
if (this.#frame) cancelAnimationFrame(this.#frame);

let encoded = compressToEncodedURIComponent(rawText);
Expand All @@ -182,35 +183,42 @@ export class FileURIComponent {
...qps,
};

this.#frame = requestAnimationFrame(async () => {
if (isDestroyed(this) || isDestroying(this)) {
return;
}
return new Promise<void>((resolve) => {
this.#frame = requestAnimationFrame(async () => {
if (isDestroyed(this) || isDestroying(this)) {
resolve();

/**
* Debounce so we are kinder on the CPU
*/
await new Promise((resolve) => setTimeout(resolve, DEBOUNCE_MS));
return;
}

if (isDestroyed(this) || isDestroying(this)) {
return;
}
/**
* Debounce so we are kinder on the CPU
*/
await new Promise((resolve) => setTimeout(resolve, DEBOUNCE_MS));

// On initial load, if we call #updateQPs,
// we may not have a currentURL, because the first transition has yet to complete
let base = this.router.currentURL?.split('?')[0];
if (isDestroyed(this) || isDestroying(this)) {
resolve();

if (macroCondition(isTesting())) {
// eslint-disable-next-line @typescript-eslint/no-explicit-any
base ??= (this.router as any) /* private API? */?.location?.path;
} else {
base ??= window.location.pathname;
}
return;
}

// On initial load, if we call #updateQPs,
// we may not have a currentURL, because the first transition has yet to complete
let base = this.router.currentURL?.split('?')[0];

if (macroCondition(isTesting())) {
// eslint-disable-next-line @typescript-eslint/no-explicit-any
base ??= (this.router as any) /* private API? */?.location?.path;
} else {
base ??= window.location.pathname;
}

let next = `${base}?${qps}`;
let next = `${base}?${qps}`;

this.router.replaceWith(next);
this.#text = rawText;
this.router.replaceWith(next);
this.#text = rawText;
resolve();
});
});
};
}
2 changes: 1 addition & 1 deletion apps/repl/tests/application/-page/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ export class Page extends PageObject {

let url = currentURL();

assert(`Expected an URL, got ${url}`, url);
assert(`Expected an URL -- via currentURL(), got ${url}`, url);

let [, search] = url.split('?');
let query = new URLSearchParams(search);
Expand Down
3 changes: 3 additions & 0 deletions apps/repl/tests/test-helper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,9 @@ Object.assign(window, { getSettledState, getPendingWaiterState, currentURL, curr

setup(QUnit.assert);

QUnit.testStart(() => {
localStorage.clear();
});
QUnit.testDone(resetOnerror);

start();

0 comments on commit 9af42ec

Please sign in to comment.