Skip to content

fix: ensure document.visibilityState aligns with the visibility of the TopLevelWindow - #19988

Merged
MarshallOfSound merged 2 commits into
masterfrom
visibility-state
Sep 5, 2019
Merged

MarshallOfSound merged 2 commits into
masterfrom
visibility-state

Conversation

@MarshallOfSound

Copy link
Copy Markdown
Member

The best way to see what this changes is to review the bunch of new tests I added. Basically this fixes the following two things and a bunch of edge cases

  • Creating a window with show: false results in document.visibilityState === 'visible'. This is fundamentally wrong so now it's hidden, but due to a technical constraint imposed by the ready-to-show event we only set it to hidden initially if folks use a new paintWhenInitiallyHidden: false option when constructing their window.
  • Calling win.hide() and win.show() did not modify visibilityState resulting in backgrounded windows not being throttled correctly and CPU usage being insane while backgrounded. This is fixed in this PR, no other changes for users needed.

Long term we should make paintWhenInitiallyHidden: false the default but for now let's keep this change non breaking. The reason we need paintWhenInitiallyHidden is because previously show: false didn't set the renderer as hidden so it painted, that first paint is used to fire the ready-to-show event. If we don't paint that event never fires (and I've documented this in this PR).

Notes: Fixed several cases where document.visibilityState would be incorrect. The win.show() and win.hide() methods now correctly update visibility state

@electron-cation electron-cation Bot added the new-pr 🌱 PR opened recently label Aug 27, 2019
@electron-cation electron-cation Bot removed the new-pr 🌱 PR opened recently label Aug 28, 2019

@zcbenz zcbenz left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would this affect the behavior of setBackgroundThrottling API?

And should this be a feat as it adds a new option?

@MarshallOfSound

Copy link
Copy Markdown
Member Author

Would this affect the behavior of setBackgroundThrottling API?

Initial tests showed it didn't change the behavior of that API, our patch short circuits this logic so even these extra calls don't affect it.

And should this be a feat as it adds a new option?

🤷‍♂ Technically yes, I added that new option to retain backwards compatibility. I'd like to find some form of this change that can land in 7-0-x.

@zcbenz zcbenz left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for clarification, this looks good to me.

@MarshallOfSound
MarshallOfSound merged commit 1376229 into master Sep 5, 2019
@MarshallOfSound
MarshallOfSound deleted the visibility-state branch September 5, 2019 17:56
@release-clerk

release-clerk Bot commented Sep 5, 2019

Copy link
Copy Markdown

Release Notes Persisted

Fixed several cases where document.visibilityState would be incorrect. The win.show() and win.hide() methods now correctly update visibility state

@trop

trop Bot commented Sep 5, 2019

Copy link
Copy Markdown
Contributor

I have automatically backported this PR to "7-0-x", please check out #20134

poiru added a commit to poiru/electron that referenced this pull request Dec 3, 2019
In electron#20829, we fixed compositor recycling when switching between
BrowserViews, but it turns out that there is one additional case that we
need to handle. When we create a completely new BrowserView instance, it
starts of as visible (even when it hasn't been added to the window),
which means that it will need its own compositor instead of using the
recycled compositor.

To fix this, lets make BrowserViews hidden by default until they're
added to the window. See also electron#19988. This is a potentially breaking
change given that the initial value of `document.visibilityState` will
now be `hidden`, but given the experimental status of BrowserViews, I
think this is a fine change to make. The old behavior can be restored
with `webPreferences: { show: true }`.

Notes: Fix compositor recycling when creating new BrowserView
poiru added a commit to poiru/electron that referenced this pull request Dec 4, 2019
In electron#20829, we fixed compositor recycling when switching between
BrowserViews, but it turns out that there is one additional case that we
need to handle. When we create a completely new BrowserView instance, it
starts of as visible (even when it hasn't been added to the window),
which means that it will need its own compositor instead of using the
recycled compositor.

To fix this, lets make BrowserViews hidden by default until they're
added to the window. See also electron#19988. This is a potentially breaking
change given that the initial value of `document.visibilityState` will
now be `hidden`, but given the experimental status of BrowserViews, I
think this is a fine change to make. The old behavior can be restored
with `webPreferences: { show: true }`.

Notes: Fix compositor recycling when creating new BrowserView
poiru added a commit to poiru/electron that referenced this pull request Dec 4, 2019
In electron#20829, we fixed compositor recycling when switching between
BrowserViews, but it turns out that there is one additional case that we
need to handle. When we create a completely new BrowserView instance, it
starts of as visible (even when it hasn't been added to the window),
which means that it will need its own compositor instead of using the
recycled compositor.

To fix this, lets make BrowserViews hidden by default until they're
added to the window. See also electron#19988. This is a potentially breaking
change given that the initial value of `document.visibilityState` will
now be `hidden`, but given the experimental status of BrowserViews, I
think this is a fine change to make. The old behavior can be restored
with `webPreferences: { show: true }`.

Notes: Fix compositor recycling when creating new BrowserView
poiru added a commit to poiru/electron that referenced this pull request Dec 5, 2019
Backport of electron#21372. This also backports a tiny bit of electron#19988.

Notes: Fix flicker when switching between BrowserViews after creating new BrowserView
@trop

trop Bot commented Dec 5, 2019

Copy link
Copy Markdown
Contributor

@poiru has manually backported this PR to "6-1-x", please check out #21396

@trop trop Bot added the in-flight/6-1-x label Dec 5, 2019
MarshallOfSound pushed a commit that referenced this pull request Dec 5, 2019
In #20829, we fixed compositor recycling when switching between
BrowserViews, but it turns out that there is one additional case that we
need to handle. When we create a completely new BrowserView instance, it
starts of as visible (even when it hasn't been added to the window),
which means that it will need its own compositor instead of using the
recycled compositor.

To fix this, lets make BrowserViews hidden by default until they're
added to the window. See also #19988. This is a potentially breaking
change given that the initial value of `document.visibilityState` will
now be `hidden`, but given the experimental status of BrowserViews, I
think this is a fine change to make. The old behavior can be restored
with `webPreferences: { show: true }`.

Notes: Fix compositor recycling when creating new BrowserView
trop Bot pushed a commit that referenced this pull request Dec 5, 2019
In #20829, we fixed compositor recycling when switching between
BrowserViews, but it turns out that there is one additional case that we
need to handle. When we create a completely new BrowserView instance, it
starts of as visible (even when it hasn't been added to the window),
which means that it will need its own compositor instead of using the
recycled compositor.

To fix this, lets make BrowserViews hidden by default until they're
added to the window. See also #19988. This is a potentially breaking
change given that the initial value of `document.visibilityState` will
now be `hidden`, but given the experimental status of BrowserViews, I
think this is a fine change to make. The old behavior can be restored
with `webPreferences: { show: true }`.

Notes: Fix compositor recycling when creating new BrowserView
trop Bot pushed a commit that referenced this pull request Dec 5, 2019
In #20829, we fixed compositor recycling when switching between
BrowserViews, but it turns out that there is one additional case that we
need to handle. When we create a completely new BrowserView instance, it
starts of as visible (even when it hasn't been added to the window),
which means that it will need its own compositor instead of using the
recycled compositor.

To fix this, lets make BrowserViews hidden by default until they're
added to the window. See also #19988. This is a potentially breaking
change given that the initial value of `document.visibilityState` will
now be `hidden`, but given the experimental status of BrowserViews, I
think this is a fine change to make. The old behavior can be restored
with `webPreferences: { show: true }`.

Notes: Fix compositor recycling when creating new BrowserView
ckerr pushed a commit that referenced this pull request Dec 5, 2019
In #20829, we fixed compositor recycling when switching between
BrowserViews, but it turns out that there is one additional case that we
need to handle. When we create a completely new BrowserView instance, it
starts of as visible (even when it hasn't been added to the window),
which means that it will need its own compositor instead of using the
recycled compositor.

To fix this, lets make BrowserViews hidden by default until they're
added to the window. See also #19988. This is a potentially breaking
change given that the initial value of `document.visibilityState` will
now be `hidden`, but given the experimental status of BrowserViews, I
think this is a fine change to make. The old behavior can be restored
with `webPreferences: { show: true }`.

Notes: Fix compositor recycling when creating new BrowserView
MarshallOfSound pushed a commit that referenced this pull request Dec 6, 2019
…21396)

Backport of #21372. This also backports a tiny bit of #19988.

Notes: Fix flicker when switching between BrowserViews after creating new BrowserView
zcbenz pushed a commit that referenced this pull request Dec 10, 2019
In #20829, we fixed compositor recycling when switching between
BrowserViews, but it turns out that there is one additional case that we
need to handle. When we create a completely new BrowserView instance, it
starts of as visible (even when it hasn't been added to the window),
which means that it will need its own compositor instead of using the
recycled compositor.

To fix this, lets make BrowserViews hidden by default until they're
added to the window. See also #19988. This is a potentially breaking
change given that the initial value of `document.visibilityState` will
now be `hidden`, but given the experimental status of BrowserViews, I
think this is a fine change to make. The old behavior can be restored
with `webPreferences: { show: true }`.

Notes: Fix compositor recycling when creating new BrowserView
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants