Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix for lag when opening sidebar using toggle sidebar brick #8295

Merged
merged 2 commits into from
Apr 19, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 19 additions & 9 deletions src/contentScript/sidebarController.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -48,9 +48,28 @@ import { showMySidePanel } from "@/background/messenger/strict/api";
import { getSidebarElement } from "@/contentScript/sidebarDomControllerLite";
import focusController from "@/utils/focusController";
import selectionController from "@/utils/selectionController";
import { messenger } from "webext-messenger";
import { getSidebarTargetForCurrentTab } from "@/utils/sidePanelUtils";

const HIDE_SIDEBAR_EVENT_NAME = "pixiebrix:hideSidebar";

/*
* Only one check at a time
* Cannot throttle because subsequent checks need to be able to be made immediately
*/
const isSidePanelOpenMv3 = memoizeUntilSettled(async () => {
try {
await messenger(
"SIDEBAR_PING",
{ retry: false },
await getSidebarTargetForCurrentTab(),
);
return true;
} catch {
return false;
}
});

export const isSidePanelOpen = isMV3()
? isSidePanelOpenMv3
: sidebarMv2.isSidebarFrameVisible;
Expand All @@ -69,15 +88,6 @@ const pingSidebar = memoizeUntilSettled(
}, 1000) as () => Promise<void>,
);

async function isSidePanelOpenMv3() {
try {
await pingSidebar();
return true;
} catch {
return false;
}
}

/**
* Event listeners triggered when the sidebar shows and is ready to receive messages.
*/
Expand Down
Loading