Skip to content

Commit

Permalink
fix: add delay on route change
Browse files Browse the repository at this point in the history
  • Loading branch information
pnd280 committed Sep 19, 2024
1 parent 8fdadd5 commit 7bc56cb
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 3 deletions.
2 changes: 2 additions & 0 deletions docs/changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ _Release date: 19th Sep, 2024_
- **IMPROVE**: Redesigned the Focus Selector UI. Now it's more intuitive for new users.
- **IMPROVE**: Significantly reduce the chance of being stuck in infinite message generating state.

- **FIX**: Fixed minor bugs.

## v0.0.2.0

_Release date: 15th Sep, 2024_
Expand Down
9 changes: 6 additions & 3 deletions src/content-script/main-world/router.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import { RouterEvent } from "@/types/ws.types";
import { DomSelectors } from "@/utils/DomSelectors";
import { mainWorldExec } from "@/utils/hof";
import UiUtils from "@/utils/UiUtils";
import { whereAmI } from "@/utils/utils";
import { sleep, whereAmI } from "@/utils/utils";

type NextRouter = typeof window.next;

Expand Down Expand Up @@ -135,12 +135,13 @@ class Router {
private async waitForRouteChangeComplete(
location: ReturnType<typeof whereAmI>,
) {
await sleep(1000);

return new Promise<void>((resolve) => {
const conditions: Partial<Record<typeof location, () => boolean>> = {
thread: () => {
try {
if (UiUtils.getMessageBlocks(true).length < 1) return false;
return true;
return UiUtils.getMessageBlocks(true).length >= 1;
} catch {
return false;
}
Expand All @@ -156,7 +157,9 @@ class Router {

const interval = setInterval(() => {
if (condition()) {
console.log("condition met");
clearInterval(interval);

return resolve();
}
}, 100);
Expand Down

0 comments on commit 7bc56cb

Please sign in to comment.