-
Notifications
You must be signed in to change notification settings - Fork 25
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
Sidepanel open check failing in some browsers #8271
Conversation
/** | ||
* Determines whether the sidebar is open. | ||
* @returns false when it's definitely closed or 'unknown' when it cannot be determined, | ||
* because the extra padding might be caused by the dev tools being open on the side | ||
* or due to another sidebar | ||
*/ | ||
// The type cannot be `undefined` due to strictNullChecks | ||
function isSidePanelOpenSync(): false | "unknown" { | ||
if (!isMV3()) { | ||
throw new Error("isSidePanelOpenSync is only available in MV3"); | ||
} | ||
|
||
if (!globalThis.window) { | ||
return "unknown"; | ||
} | ||
|
||
return window.outerWidth - window.innerWidth > MINIMUM_SIDEBAR_WIDTH | ||
? "unknown" | ||
: false; | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Relocated function closer to the call site since it's no longer used by isSidePanelOpenMv3
if (isSidePanelOpenSync() === false) { | ||
return false; | ||
} | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The proposed fix. Removing means more messenger calls, but it prevents false negatives due to bad inner/outer width calculations
return "unknown"; | ||
} | ||
|
||
return window.outerWidth - window.innerWidth > MINIMUM_SIDEBAR_WIDTH |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't know much about details of outerWidth/innerWidth. Should we just be saying if there's any difference then it's unknown? What's the benefit to having the minimum difference?
cc @fregante
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It does seem like on my machine + chrome, the outerWidth is always equal to the inner width when the sidebar is closed. However, I could imagine that could not be the case on different OS's / Edge. Ex. if you have a persistent scrollbar or not.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We could potentially change to window.outerWidth > window.innerWidth
. I'm not 100% confident here since I've never been able to reproduce. I think this failing is far less likely to be problematic when called by sidePanelOnCloseSignal
, which is the only remaining usage of isSidePanelOpenSync
in this PR
@@ -513,6 +488,27 @@ export function getReservedPanelEntries(): { | |||
}; | |||
} | |||
|
|||
/** | |||
* Determines whether the sidebar is open. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Provide some comment on when this should be used vs. other ways to determine?
Can we ping the w3c folks on this feature request so we don't have to make such a hack? 😅 |
Codecov ReportAttention: Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #8271 +/- ##
==========================================
+ Coverage 73.49% 73.51% +0.02%
==========================================
Files 1325 1325
Lines 40864 40851 -13
Branches 7566 7561 -5
==========================================
Hits 30032 30032
+ Misses 10832 10819 -13 ☔ View full report in Codecov by Sentry. |
No loom links were found in the first post. Please add one there if you'd like to it to appear on Slack. Do not edit this comment manually. |
* or due to another sidebar | ||
*/ | ||
// The type cannot be `undefined` due to strictNullChecks | ||
function isSidePanelOpenSync(): false | "unknown" { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If this function is not reliable, then it should just be dropped. I don’t think there's a scenario in which we need it to be sync, right?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I was avoiding making changes to sidePanelOnCloseSignal
, but it's should be safe. I'll drop it.
} | ||
async function isSidePanelOpenMv3() { | ||
return memoizeUntilSettled( | ||
throttle(async () => { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
These aren't hooks, they're being used incorrectly.
- two
isSidePanelOpenMv3()
will still send two messages - same for
throttle
You're probably looking for:
const isSidePanelOpenMv3 = throttle(memoizeUntilSettled(fn));
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Now that I look at the file, the pingSidebar
function below does the same thing. You're probably looking for:
async function isSidePanelOpenMv3() {
try {
await pingSidebar()
return true
} catch {
return false
}
}
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This was my initial inclination, but I assumed the original implementation used messenger
directly for a reason.
@@ -113,6 +74,16 @@ const pingSidebar = memoizeUntilSettled( | |||
}, 1000) as () => Promise<void>, | |||
); | |||
|
|||
// This method is exclusive to the content script, don't export it |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Outdated now that it doesn't use the DOM/window
, it can be called from anywhere
What does this PR do?
Discussion
Important
SIDEBAR_PING
is anoop
, but we're still increasing the number of messenger callsMINIMUM_SIDEBAR_WIDTH
, but as it is already 300, I don't think that would help. It's possible that something is going wrong with the inner and outer width checksChecklist