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

Sidepanel open check failing in some browsers #8271

Merged
merged 7 commits into from
Apr 18, 2024

Conversation

grahamlangford
Copy link
Collaborator

What does this PR do?

  • Potentially fixes an issue where the side panel would hang in a loading state with the reserved panels showing

Discussion

  • I've never been able to reproduce the issue (on Mac or Windows via Parallel)
  • When the width check ever returns false, side panel hangs
  • In customer calls, we were able to determine that the sidebar was being reported as not visible

Important

  • I'm not sure about the performance implications of always pinging
    • SIDEBAR_PING is a noop, but we're still increasing the number of messenger calls
    • We always ping using the messenger when we think the side panel might be open, though, so it's probably ok
  • Alternatively, we could try reducing the MINIMUM_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 checks

Checklist

@grahamlangford grahamlangford added bug Something isn't working customer Required for a customer projct labels Apr 17, 2024
@grahamlangford grahamlangford self-assigned this Apr 17, 2024
Comment on lines -63 to -82
/**
* 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;
}
Copy link
Collaborator Author

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

Comment on lines -86 to -89
if (isSidePanelOpenSync() === false) {
return false;
}

Copy link
Collaborator Author

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
Copy link
Contributor

@twschiller twschiller Apr 17, 2024

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

Copy link
Collaborator

@fungairino fungairino Apr 17, 2024

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.

Copy link
Collaborator Author

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.
Copy link
Contributor

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?

@fungairino
Copy link
Collaborator

Can we ping the w3c folks on this feature request so we don't have to make such a hack? 😅
w3c/webextensions#517

@fungairino
Copy link
Collaborator

Copy link

codecov bot commented Apr 17, 2024

Codecov Report

Attention: Patch coverage is 0% with 7 lines in your changes are missing coverage. Please review.

Project coverage is 73.51%. Comparing base (9f3aced) to head (5f87131).
Report is 5 commits behind head on main.

Files Patch % Lines
src/contentScript/sidebarController.tsx 0.00% 7 Missing ⚠️
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.
📢 Have feedback on the report? Share it here.

Copy link

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" {
Copy link
Contributor

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?

Copy link
Collaborator Author

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 () => {
Copy link
Contributor

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));

Copy link
Contributor

@fregante fregante Apr 18, 2024

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
  }
}

Copy link
Collaborator Author

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
Copy link
Contributor

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

@grahamlangford grahamlangford merged commit f73b84b into main Apr 18, 2024
22 checks passed
@grahamlangford grahamlangford deleted the fix-side-panel-never-loading branch April 18, 2024 14:56
@grahamlangford grahamlangford added this to the 1.8.13 milestone Apr 22, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working customer Required for a customer projct
Development

Successfully merging this pull request may close these issues.

4 participants