You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
[Bug]: Page content resizes with noticable delay #36280
Latest Chrome version now syncs window and render sizes.
Screen.Recording.2021-08-14.at.08.17.12.mov
Yet still, if relayout takes a lot of time, this split still occurs, especially for more complex layouts and because chrome is not optimizing for relayout performance.
Electron aligns with Chrome's behavior: we try to reduce delay as much as possible, but unfortunately the design of Chrome's layout engine does not have the feature to fully synchronize window resize with layout change for all pages.
So I'm closing this as won't fix because we are unable to change Chrome's layout engine to implement this feature.
But if resizing a page has no delay in Chrome but has delay in Electron, then it would be a bug that we want to fix though.
Chrome stable has had smooth resizing for a long time, esp with the metal angle backend: --use-angle=metal.
Configuring the flag properly initializes metal on electron, but electron still has a massive synchronization problem when resizing the window, as apposed to chrome stable.
FWIW If anyone is debugging on Apple Silicon, it's probably better to profile using metal because on chrome stable it also eliminates overhead from the ogl backend.
I have been meaning to get a debug build of electron to profile myself, but I haven't had the time yet.
I may have a similar issue, noticing it with Microsoft Teams and VS Code, although the issue was only noticeable as of today for whatever reason. I'm on Ventura 13.0.1 on an M1. Let me know if I should post on those two respective repos instead!
This is clearing the visual_properties_ack_pending_ flag prior to calling SynchronizeVisualProperties, which then causes the early exit to be skipped while there are prior visual properties being processed. This causes a queue of updates, which get behind and as resizing continues it gets further delayed.
This seems to affect OSX mostly, it's unclear exactly why (but I suspect) that there's simply more events being pushed.
@nkallen, this is a tricky issue because it's hard to objectively test it given the nature of the bug. Regarding the Windows regression between Electron 27 and 28, I've tried poking at it and I think I can see a behavior difference with a hacky test case, but I'd like to see if it also helps in your test. Can you try setting the opacity value for the BrowserWindow? Anything that's not 1.0 should work, if you set it to something like 0.99999 the window will still look fully opaque. Setting it to a non-1.0 value will effectively undo the change in #39895, which I have a sneaking suspicion might be related to the regression you're seeing.
@nkallen, this is a tricky issue because it's hard to objectively test it given the nature of the bug. Regarding the Windows regression between Electron 27 and 28, I've tried poking at it and I think I can see a behavior difference
@dsanders11 are you able to observe the behavior in vscode and linear? the picture here #36280 (comment) is from vscode where multiple sizes of the window are rendered to the same framebuffer simultaneously. I have two windows machines with near top-end hardware and observe this behavior on both of them, so I'm assuming it's not hard to reproduce? FWIW, going to linear's website with Chrome or Edge, the same problem occurs on windows.
are you able to observe the behavior in vscode and linear? [...] so I'm assuming it's not hard to reproduce
If the repro case is just manually resizing the window rapidly (like in https://github.com/user-attachments/assets/046e905d-c20f-47e1-996e-c9b5fff38de4) and trying to visually notice the issue while UI elements are reflowing, I don't consider that easy to reproduce. I messed around with it on Windows for a while but most of the time could not definitively say if it was happening or not until I hacked together a test case that rapidly does the resizing on an interval and some differences became visible. So while I can somewhat observe it, it's not an objective test (e.g. something we can automate with a pass/fail).
Please try changing the opacity setting as I recommended in the previous comment to see if you notice a change in behavior.
I'm sorry about my previous grumpy post. I'll test it tomorrow. It's fairly time consuming for us to test it because we need to use a fork without the pointer cage. I recommend testing it first on vscode while making a video. It should be pretty clear if you pause the video whether the problem has gone away.
I think that the opacity trick completely fixes the framebuffer clobbering bug introduced in Electron v28. The improvement is huge, please see the attached video and freeze-frames.
Thank you so much for finding this fix! I'm assuming you can find a solution where it won't be necessary to set the opacity? This satisfies my bug bounty and you earned the money. Please contact me (nick at plasticity dot xyz). This improvement will benefit vscode, linear, Plasticity, and every modern Electron app on windows.
The older bug (much older than v28), where the window resizes at a different framerate than reflow, is still there, unfortunately. This is also called out in the video. I am willing to put an additional $10k bounty for a fix for this bug. This should be fixed on both Windows and Mac.
Thank you so much for finding this fix! I'm assuming you can find a solution where it won't be necessary to set the opacity?
I still need to do my due diligence and confirm with a build that the issue is definitely caused by #39895 and not just a coincidence regarding transparency, but then I'll discuss with other maintainers about reverting #39895 in the short-term as the negative impact you're seeing is larger than the issue that PR aimed to fix.
Long-term this will still require more debugging/research. The issue the opacity trick fixes might be an interaction between the original bug (reflow lagging noticeably behind resizing) and that PR - when the window is marked as transparent, it may prevent the old framebuffers from being visible in the dead area (which is otherwise a black bar in your videos).
Ideally we can get some automated testing around these cases otherwise there's a high risk of regression.
It does seem a challenge to write a unit test for something like this. Maybe a complicated layout where everything has a bgcolor that's a hash of the timestamp. Resizing the window and grabbing screenshots should always show a uniform color.
Electron 34,windows 10, it's even worse. Before the new area is rendered, the old content is displayed, making it look like there's an overlap on the interface. This might be an optimization of Chromium, but it looks terrible.
The following functions and flags mitigate the frame tearing issue:
app.disableHardwareAcceleration()
--use-angle=warp
--use-angle=vulkan
--use-gl=desktop
--use-gl=egl
--use-gl=osmesa
--use-gl=swiftshader
The following flags are affected by the frame tearing issue:
--use-angle=d3d11 (this is currently the default on Windows)
--use-angle=gl (falls back to Direct 3D on Windows, see chrome://gpu/)
None of the working flags are production ready in my opinion. They are either too slow or lack good driver support.
However, these workarounds pointed me into the right direction. They showed that the issue was in a code path that was only used with the ANGLE Direct3D backend.
I did not follow the transparency lead further. However, we'll get back to transparency later.
What causes the issue?
Under the hood, there are two separate issues:
An issue where different GPU operations are out of sync, leading to previously drawn pixels being shown.
An issue where frames are being resized, leading to gutter that shows stale pixels.
Both of them lead to stale pixels in different situations. Both need to be fixed to fully resolve the issue.
I have fixes for both of them. One has already been merged into Chromium. The other will hopefully be merged soon.
But let's go through it slowly.
When using the ANGLE Direct 3D backend, Chromium uses the Windows DirectComposition API for drawing the window contents.
DirectComposition differs from all other output devices in Chromium. The DirectComposition OutputSurface has the capability supports_viewporter (source link 1, source link 2).
An output surface is a bitmap that can be drawn to, often backed by a GPU texture.
Without supports_viewporter, whenever the window size changes, Chromium will create a new output surface matching the new window size. Then it will draw on that surface and show it.
supports_viewporter tries to reduce these costly surface allocations. With supports_viewporter, Chromium will not allocate a new surface on every resize. Instead, it will allocate a surface that is too large for what we need to draw. Then it will only paint to and show a certain sub-rectangle (the "viewport") of that surface on screen. The other parts of the surface are not supposed to be shown on screen.
This is supposed to make resizing more efficient because all Chromium needs to do is pad the surface to the proper width and height instead of allocating a new surface on every resize. This surface resize logic lives here.
Here's what that looks like:
The blue rectangle is our surface. The green area is our viewport, i.e., the area of our surface that is supposed to be visible and that we actively draw to. The red rectangle is our clip rect(angle), i.e., the part of the surface that is actually being shown on screen.
As a performance optimization, only the viewport (the green area) is repainted when we get a new frame. The rest is left unchanged. This is important. We only ever repaint the green viewport. We don't update the areas outside of the viewport.
When we resize the window, what's supposed to happen is that in an atomic transaction (= at the exact same time) we repaint the viewport (= the area that's supposed to be visible on screen) and then update the clip rect to clip the surface to the new viewport size.
After the resize, it should look like this:
And that's where we get to the first of our two bugs.
First bug
Sometimes these operations can get out of sync. For example, the clip rect might get updated before the viewport is repainted. Then we get a result like this:
We still show the old frame in the green viewport. But the clip rect has become larger and we show areas of the surface that we haven't repainted yet.
On the first resize of a window, these areas would be black. On the second resize, those areas would be filled with old pixel values. They would show whatever we have previously painted in those areas.
Similarly, in a certain edge case while making the window smaller, we might sometimes repaint the viewport before we update the clip rect.
Then parts of the clip rect might still show the previous frame because the new frame is smaller and we did not repaint any areas beyond the new viewport.
Here's what's important to understand: both functions return synchronously on the CPU. However, what they do is they schedule tasks that run asynchronously on the GPU at a later time. Windows and its services (such as DWM) decide when they will run and in which order. So they take effect asynchronously, and not always within the same frame.
Unfortunately, Windows provides no way for us to synchronize those operations. So we need to find other approaches to fix this.
Here are the two options that I'm currently evaluating with the Chromium maintainers in crrev.com/c/7115438:
While resizing, paint all previously drawn areas outside of the viewport transparent. This makes those areas invisible. It fixes the artifacts.
While resizing, switch from an IDXGISwapChain1 to a DirectComposition surface which synchronizes updates with IDCompositionDevice::Commit. This also fixes the artifacts.
I'm in favor of the first option because it leads to faster resizes than the second option. It's what I've implemented in crrev.com/c/7115438. But we will see which solution we will ultimately land on.
Second bug
In addition to this first bug, there was a second bug which also led to stale pixels.
When the user resizes the window, Chromium needs to redraw the contents of the window for the new window size. This takes some time. The new frame isn't ready immediately.
Here's a sequence of frames that demonstrates this:
At a certain time during the resize, Windows tells us: "The window is 1,000 pixels wide." But the frames that the browser compositor produces are lagging behind. The last frame we have painted might be 600 pixels wide.
Historically, Chromium used to skip frames where the width of the window did not match the width of the frame that it last painted. It would decide to just not update the window.
However, that would often lead to the window contents not being updated at all until the resize operation was finished.
So in 2015 someone decided: "Why not show these frames? They might not match the window size perfectly, but at least we can show something."
It would lead to gutter, but at that time the gutter was black. So that was better than the previous implementation.
Now, 10 years later with DirectComposition, that gutter is often filled with stale pixels.
Let's look at what's happening there:
Every frame consists of multiple render passes. The render passes represent the various things that should be drawn on screen. From complicated bitmaps to rectangles filled with solid colors.
Every frame has a root render pass, which contains all other render passes and glues them together. (Render passes are arranged in a tree structure and the root render pass is the root of that tree.)
So now during a resize, we'd get to a point where we know the window is 1,000 pixels wide. Accordingly, we'd adjust the viewport of our output surface to also be 1,000 pixels wide. But the frame that we just received is only 600 pixels wide.
The optimization from 2015 would then go and change the width of the root render pass to also be 1,000 pixels. But it wouldn't change what the render passes would actually draw on screen. They'd still only contain instructions to draw a picture that is 600 pixels wide.
Here's what that would look like:
The yellow area is the area in which the render passes of the frame actually drew something. It's 600 pixels wide.
However, our green viewport and our red clip rect are 1,000 pixels wide. That's the area that we show on screen.
After all, the width attribute of the root render pass claimed that it would redraw the full area of 1,000 pixels.
But because we had no draw instructions for the 400 pixels on the right, those areas didn't get updated.
On the first resize, we'd show black pixels there. (That's the color that we initialize the surface with.)
On subsequent resizes, those areas would show whatever was drawn to them before. We'd see stale pixels.
As mentioned before, we merged a fix for this issue into Chromium today.
The fix changes what we do when we receive a frame with a different size than our window. Instead of resizing the frame and adding gutter that contains stale pixels, we resize our viewport and our clip rect.
We clip our surface to the size of the frame that we received. We don't show anything beyond the 600 pixels that we have draw instructions for.
Voila, no more gutter, no more stale pixels!
(Side note: Without supports_viewporter, this would be an expensive operation because it would allocate a new output surface. However, with DirectComposition, we use the "viewporter" feature. So we don't reallocate the surface when we change the viewport size. We just make a different portion of it visible. Thus, it is a cheap operation.)
Why did the transparency workaround help?
skia_renderer.cc contains the following lines of code:
if (current_frame()->current_render_pass->has_transparent_background) {
ClearCanvas(SkColors::kTransparent);
}
If the background of whatever was being painted was partially or fully transparent, the code would fill the viewport with a transparent color before drawing the render passes on the surface.
This would eliminate most (but not all) of the stale pixels. It helped whenever the stale pixels were within the viewport. It did not help when we'd show stale pixels that were outside of the viewport.
Next steps
My fix for the second bug landed in Chromium today via crrev.com/c/7156576. On my machine, fixing the second bug removes about half of the stale pixels. I'll backport the fix to Electron within the next few days.
I also have a fix for the first bug up for review in crrev.com/c/7115438. It works and fully removes the remaining stale pixels. Right now, it's mostly a matter of communicating with the Chromium maintainers to make sure we don't break any non-Window or non-DirectComposition use cases and to choose the best of all available solutions. Once a fix is merged, I will backport it to Electron as well.
Thanks
Big thanks to @nkallen and Plasticity for funding this work! Also, thanks to Michael Tang and Vasiliy Telezhnikov from the Chromium team for their help.
Last words
This has been the hardest bug I have ever worked on. (And I have worked on many hard bugs in 18 years of writing software.) But it has also been one of the most fun projects I have ever worked on.
There is more nuance to it than I could include in this write-up. I had to leave out certain details for the sake of simplicity.
Reacted by Aluisio, David, StarchaserDev, Darshan Sen, Kilian Valkhof, Nick Kallen, Oleguer Llopart, Calvin, Jurj Andrei George, Ryan Fitzgerald and 5 more
Reacted by hyrious, David Babenko-Sanders, David, Kai Shimada, StarchaserDev, Benjamin Pasero, Darshan Sen, Erick Zhao, Kilian Valkhof, Oleguer Llopart and 12 more
All patches have been merged into Chromium! (#1, #2, #3, #4) 🎉
One of them has been merged into Electron 39 (but is not part of any release yet).
I have a pull request open to backport the other patches to Electron 39, too. (Reviews welcome!)
The patches will make it into Electron v40 and v41 through one of the next Chromium rolls.
The patches fully fix the issue where old pixels would show up during window resizes on Windows (highlighted in red):
Where to take it from here
The following issues still require investigation:
1. Windows + macOS: In Electron, web content resizes slower than in Chromium.
I'd assume that this issue is easier to solve than the second issue below.
It might be caused by differences between Electron's window resize code and Chromium's window resize code. There's a good chance its root is in the Electron source code, not in Chromium.
It also has a higher impact than the second issue.
2. Windows only: In both Electron and Chromium, the size of the compositor frames (the size of the drawn website) lags behind the window size.
This issue needs to be fixed upstream in Chromium. It might require Windows-specific optimizations of the compositor (cc) code and maybe also optimizations in the display compositor (viz). That could be a large project.
We should start by reporting it to Chromium upstream. I haven't see an issue for it in their bug tracker.
I noticed that the last two upstream patches just barely missed the deadline for Chromium 144 (which Electron 40 is based on), so I'll backport the patches to Electron 40, too. (And then I'll also do main, because why not?)
Reacted by CryUshio, Jeesson, Andrii Oriekhov, Mel Bourgeois, Minyu Wang, Dennis Boldt, Kanishk Ranjan, Bardiya, Lang, Nafisa and 1 more
Activity
zcbenz commentedon Nov 8, 2022
Electron aligns with Chrome's behavior: we try to reduce delay as much as possible, but unfortunately the design of Chrome's layout engine does not have the feature to fully synchronize window resize with layout change for all pages.
So I'm closing this as won't fix because we are unable to change Chrome's layout engine to implement this feature.
But if resizing a page has no delay in Chrome but has delay in Electron, then it would be a bug that we want to fix though.
CryUshio commentedon Nov 8, 2022
@zcbenz It seems that resizing a page has delay in Electron.
Resizing in Chrome:
2022-11-08.19.40.46.mov
Resizing in Electron 21.2.2:
2022-11-08.19.41.51.mov
You can see the white block on the right edge in Electron.
zcbenz commentedon Nov 9, 2022
Thanks for the video, yeah we should do some investigation on this.
dtzxporter commentedon Dec 14, 2022
Any progress on the investigation?
Chrome stable has had smooth resizing for a long time, esp with the metal angle backend:
--use-angle=metal.Configuring the flag properly initializes metal on electron, but electron still has a massive synchronization problem when resizing the window, as apposed to chrome stable.
FWIW If anyone is debugging on
Apple Silicon, it's probably better to profile usingmetalbecause on chrome stable it also eliminates overhead from theoglbackend.I have been meaning to get a debug build of electron to profile myself, but I haven't had the time yet.
bwong365 commentedon Dec 16, 2022
I may have a similar issue, noticing it with Microsoft Teams and VS Code, although the issue was only noticeable as of today for whatever reason. I'm on Ventura 13.0.1 on an M1. Let me know if I should post on those two respective repos instead!
Screen.Recording.2022-12-16.at.10.59.56.AM.mov
jordancde commentedon Dec 20, 2022
Bump
markh-discord commentedon Feb 28, 2023
I tracked this down and believe the resize issue was introduced by: https://chromium-review.googlesource.com/c/chromium/src/+/3118293.
This is clearing the
visual_properties_ack_pending_flag prior to callingSynchronizeVisualProperties, which then causes the early exit to be skipped while there are prior visual properties being processed. This causes a queue of updates, which get behind and as resizing continues it gets further delayed.This seems to affect OSX mostly, it's unclear exactly why (but I suspect) that there's simply more events being pushed.
codebytere commentedon Mar 1, 2023
@markh-discord this issue was originally opened in 2017 - are you referring to a new different behavior?
39 remaining items
dsanders11 commentedon Jun 2, 2025
@nkallen, this is a tricky issue because it's hard to objectively test it given the nature of the bug. Regarding the Windows regression between Electron 27 and 28, I've tried poking at it and I think I can see a behavior difference with a hacky test case, but I'd like to see if it also helps in your test. Can you try setting the
opacityvalue for theBrowserWindow? Anything that's not 1.0 should work, if you set it to something like 0.99999 the window will still look fully opaque. Setting it to a non-1.0 value will effectively undo the change in #39895, which I have a sneaking suspicion might be related to the regression you're seeing.nkallen commentedon Jun 2, 2025
@dsanders11 are you able to observe the behavior in vscode and linear? the picture here #36280 (comment) is from vscode where multiple sizes of the window are rendered to the same framebuffer simultaneously. I have two windows machines with near top-end hardware and observe this behavior on both of them, so I'm assuming it's not hard to reproduce? FWIW, going to linear's website with Chrome or Edge, the same problem occurs on windows.
dsanders11 commentedon Jun 2, 2025
If the repro case is just manually resizing the window rapidly (like in https://github.com/user-attachments/assets/046e905d-c20f-47e1-996e-c9b5fff38de4) and trying to visually notice the issue while UI elements are reflowing, I don't consider that easy to reproduce. I messed around with it on Windows for a while but most of the time could not definitively say if it was happening or not until I hacked together a test case that rapidly does the resizing on an interval and some differences became visible. So while I can somewhat observe it, it's not an objective test (e.g. something we can automate with a pass/fail).
Please try changing the
opacitysetting as I recommended in the previous comment to see if you notice a change in behavior.nkallen commentedon Jun 2, 2025
I'm sorry about my previous grumpy post. I'll test it tomorrow. It's fairly time consuming for us to test it because we need to use a fork without the pointer cage. I recommend testing it first on vscode while making a video. It should be pretty clear if you pause the video whether the problem has gone away.
nkallen commentedon Jun 3, 2025
I think that the opacity trick completely fixes the framebuffer clobbering bug introduced in Electron v28. The improvement is huge, please see the attached video and freeze-frames.
Thank you so much for finding this fix! I'm assuming you can find a solution where it won't be necessary to set the opacity? This satisfies my bug bounty and you earned the money. Please contact me (nick at plasticity dot xyz). This improvement will benefit vscode, linear, Plasticity, and every modern Electron app on windows.
The older bug (much older than v28), where the window resizes at a different framerate than reflow, is still there, unfortunately. This is also called out in the video. I am willing to put an additional $10k bounty for a fix for this bug. This should be fixed on both Windows and Mac.
(NOTE: all tests run on a fork of Electron 33.)
electron-opacity-hack.mp4
dsanders11 commentedon Jun 4, 2025
I still need to do my due diligence and confirm with a build that the issue is definitely caused by #39895 and not just a coincidence regarding transparency, but then I'll discuss with other maintainers about reverting #39895 in the short-term as the negative impact you're seeing is larger than the issue that PR aimed to fix.
Long-term this will still require more debugging/research. The issue the opacity trick fixes might be an interaction between the original bug (reflow lagging noticeably behind resizing) and that PR - when the window is marked as transparent, it may prevent the old framebuffers from being visible in the dead area (which is otherwise a black bar in your videos).
Ideally we can get some automated testing around these cases otherwise there's a high risk of regression.
nkallen commentedon Jun 4, 2025
It does seem a challenge to write a unit test for something like this. Maybe a complicated layout where everything has a bgcolor that's a hash of the timestamp. Resizing the window and grabbing screenshots should always show a uniform color.
billyang1222 commentedon Jul 2, 2025
Electron 34,windows 10, it's even worse. Before the new area is rendered, the old content is displayed, making it look like there's an overlap on the interface. This might be an optimization of Chromium, but it looks terrible.
nikwen commentedon Nov 21, 2025
@nkallen has hired me to work on the frame tearing issue where we see old or stale pixels on Windows.
I know how to solve it, and I have already landed some of the patches in Chromium.
This work and this post are sponsored by Plasticity.
This is an upstream issue
Chrome and Edge show the same frame tearing behavior.
Minimal repro
The following code is enough to see visual artifacts in Electron:
Workarounds
The following functions and flags mitigate the frame tearing issue:
app.disableHardwareAcceleration()--use-angle=warp--use-angle=vulkan--use-gl=desktop--use-gl=egl--use-gl=osmesa--use-gl=swiftshaderThe following flags are affected by the frame tearing issue:
--use-angle=d3d11(this is currently the default on Windows)--use-angle=gl(falls back to Direct 3D on Windows, seechrome://gpu/)None of the working flags are production ready in my opinion. They are either too slow or lack good driver support.
However, these workarounds pointed me into the right direction. They showed that the issue was in a code path that was only used with the ANGLE Direct3D backend.
I did not follow the transparency lead further. However, we'll get back to transparency later.
What causes the issue?
Under the hood, there are two separate issues:
Both of them lead to stale pixels in different situations. Both need to be fixed to fully resolve the issue.
I have fixes for both of them. One has already been merged into Chromium. The other will hopefully be merged soon.
But let's go through it slowly.
When using the ANGLE Direct 3D backend, Chromium uses the Windows DirectComposition API for drawing the window contents.
DirectComposition differs from all other output devices in Chromium. The DirectComposition
OutputSurfacehas the capabilitysupports_viewporter(source link 1, source link 2).An output surface is a bitmap that can be drawn to, often backed by a GPU texture.
Without
supports_viewporter, whenever the window size changes, Chromium will create a new output surface matching the new window size. Then it will draw on that surface and show it.supports_viewportertries to reduce these costly surface allocations. Withsupports_viewporter, Chromium will not allocate a new surface on every resize. Instead, it will allocate a surface that is too large for what we need to draw. Then it will only paint to and show a certain sub-rectangle (the "viewport") of that surface on screen. The other parts of the surface are not supposed to be shown on screen.This is supposed to make resizing more efficient because all Chromium needs to do is pad the surface to the proper width and height instead of allocating a new surface on every resize. This surface resize logic lives here.
Here's what that looks like:
The blue rectangle is our surface. The green area is our viewport, i.e., the area of our surface that is supposed to be visible and that we actively draw to. The red rectangle is our clip rect(angle), i.e., the part of the surface that is actually being shown on screen.
As a performance optimization, only the viewport (the green area) is repainted when we get a new frame. The rest is left unchanged. This is important. We only ever repaint the green viewport. We don't update the areas outside of the viewport.
When we resize the window, what's supposed to happen is that in an atomic transaction (= at the exact same time) we repaint the viewport (= the area that's supposed to be visible on screen) and then update the clip rect to clip the surface to the new viewport size.
After the resize, it should look like this:
And that's where we get to the first of our two bugs.
First bug
Sometimes these operations can get out of sync. For example, the clip rect might get updated before the viewport is repainted. Then we get a result like this:
We still show the old frame in the green viewport. But the clip rect has become larger and we show areas of the surface that we haven't repainted yet.
On the first resize of a window, these areas would be black. On the second resize, those areas would be filled with old pixel values. They would show whatever we have previously painted in those areas.
Similarly, in a certain edge case while making the window smaller, we might sometimes repaint the viewport before we update the clip rect.
Then parts of the clip rect might still show the previous frame because the new frame is smaller and we did not repaint any areas beyond the new viewport.
Now why do these operations not happen in sync?
We use two different Windows APIs here:
IDXGISwapChain1::Present1— This shows the new pixels on screen / updates the new viewport.IDCompositionDevice::Commit— This updates the clip rect.Here's what's important to understand: both functions return synchronously on the CPU. However, what they do is they schedule tasks that run asynchronously on the GPU at a later time. Windows and its services (such as DWM) decide when they will run and in which order. So they take effect asynchronously, and not always within the same frame.
Unfortunately, Windows provides no way for us to synchronize those operations. So we need to find other approaches to fix this.
Here are the two options that I'm currently evaluating with the Chromium maintainers in crrev.com/c/7115438:
IDXGISwapChain1to a DirectComposition surface which synchronizes updates withIDCompositionDevice::Commit. This also fixes the artifacts.I'm in favor of the first option because it leads to faster resizes than the second option. It's what I've implemented in crrev.com/c/7115438. But we will see which solution we will ultimately land on.
Second bug
In addition to this first bug, there was a second bug which also led to stale pixels.
I fixed it in crrev.com/c/7156576 and the fix was merged today! 🎉
Here's what was going on there:
When the user resizes the window, Chromium needs to redraw the contents of the window for the new window size. This takes some time. The new frame isn't ready immediately.
Here's a sequence of frames that demonstrates this:
At a certain time during the resize, Windows tells us: "The window is 1,000 pixels wide." But the frames that the browser compositor produces are lagging behind. The last frame we have painted might be 600 pixels wide.
Historically, Chromium used to skip frames where the width of the window did not match the width of the frame that it last painted. It would decide to just not update the window.
However, that would often lead to the window contents not being updated at all until the resize operation was finished.
So in 2015 someone decided: "Why not show these frames? They might not match the window size perfectly, but at least we can show something."
It would lead to gutter, but at that time the gutter was black. So that was better than the previous implementation.
Now, 10 years later with DirectComposition, that gutter is often filled with stale pixels.
Let's look at what's happening there:
Every frame consists of multiple render passes. The render passes represent the various things that should be drawn on screen. From complicated bitmaps to rectangles filled with solid colors.
Every frame has a root render pass, which contains all other render passes and glues them together. (Render passes are arranged in a tree structure and the root render pass is the root of that tree.)
So now during a resize, we'd get to a point where we know the window is 1,000 pixels wide. Accordingly, we'd adjust the viewport of our output surface to also be 1,000 pixels wide. But the frame that we just received is only 600 pixels wide.
The optimization from 2015 would then go and change the width of the root render pass to also be 1,000 pixels. But it wouldn't change what the render passes would actually draw on screen. They'd still only contain instructions to draw a picture that is 600 pixels wide.
Here's what that would look like:
The yellow area is the area in which the render passes of the frame actually drew something. It's 600 pixels wide.
However, our green viewport and our red clip rect are 1,000 pixels wide. That's the area that we show on screen.
After all, the width attribute of the root render pass claimed that it would redraw the full area of 1,000 pixels.
But because we had no draw instructions for the 400 pixels on the right, those areas didn't get updated.
On the first resize, we'd show black pixels there. (That's the color that we initialize the surface with.)
On subsequent resizes, those areas would show whatever was drawn to them before. We'd see stale pixels.
As mentioned before, we merged a fix for this issue into Chromium today.
The fix changes what we do when we receive a frame with a different size than our window. Instead of resizing the frame and adding gutter that contains stale pixels, we resize our viewport and our clip rect.
We clip our surface to the size of the frame that we received. We don't show anything beyond the 600 pixels that we have draw instructions for.
Voila, no more gutter, no more stale pixels!
(Side note: Without
supports_viewporter, this would be an expensive operation because it would allocate a new output surface. However, with DirectComposition, we use the "viewporter" feature. So we don't reallocate the surface when we change the viewport size. We just make a different portion of it visible. Thus, it is a cheap operation.)Why did the transparency workaround help?
skia_renderer.cccontains the following lines of code:If the background of whatever was being painted was partially or fully transparent, the code would fill the viewport with a transparent color before drawing the render passes on the surface.
This would eliminate most (but not all) of the stale pixels. It helped whenever the stale pixels were within the viewport. It did not help when we'd show stale pixels that were outside of the viewport.
Next steps
My fix for the second bug landed in Chromium today via crrev.com/c/7156576. On my machine, fixing the second bug removes about half of the stale pixels. I'll backport the fix to Electron within the next few days.
I also have a fix for the first bug up for review in crrev.com/c/7115438. It works and fully removes the remaining stale pixels. Right now, it's mostly a matter of communicating with the Chromium maintainers to make sure we don't break any non-Window or non-DirectComposition use cases and to choose the best of all available solutions. Once a fix is merged, I will backport it to Electron as well.
Thanks
Big thanks to @nkallen and Plasticity for funding this work! Also, thanks to Michael Tang and Vasiliy Telezhnikov from the Chromium team for their help.
Last words
This has been the hardest bug I have ever worked on. (And I have worked on many hard bugs in 18 years of writing software.) But it has also been one of the most fun projects I have ever worked on.
There is more nuance to it than I could include in this write-up. I had to leave out certain details for the sake of simplicity.
nikwen commentedon Dec 3, 2025
Update
All patches have been merged into Chromium! (#1, #2, #3, #4) 🎉
One of them has been merged into Electron 39 (but is not part of any release yet).
I have a pull request open to backport the other patches to Electron 39, too. (Reviews welcome!)
The patches will make it into Electron v40 and v41 through one of the next Chromium rolls.
The patches fully fix the issue where old pixels would show up during window resizes on Windows (highlighted in red):
Where to take it from here
The following issues still require investigation:
1. Windows + macOS: In Electron, web content resizes slower than in Chromium.
I'd assume that this issue is easier to solve than the second issue below.
It might be caused by differences between Electron's window resize code and Chromium's window resize code. There's a good chance its root is in the Electron source code, not in Chromium.
It also has a higher impact than the second issue.
2. Windows only: In both Electron and Chromium, the size of the compositor frames (the size of the drawn website) lags behind the window size.
This issue needs to be fixed upstream in Chromium. It might require Windows-specific optimizations of the compositor (
cc) code and maybe also optimizations in the display compositor (viz). That could be a large project.We should start by reporting it to Chromium upstream. I haven't see an issue for it in their bug tracker.
nikwen commentedon Dec 3, 2025
If you want to test the patches, here is a Windows x64 release build made from commit
9947a0133c70bdf8eb95771274d7677e34321753on thenikwen/backport-resize-fixes/39-x-ybranch.SHA256SUM:
845e3ea89382686985248d472d475c02a4a70c32366dea4260c9949ef65cf5a6nikwen commentedon Dec 5, 2025
The patches are part of Electron 39.2.6 now!
I noticed that the last two upstream patches just barely missed the deadline for Chromium 144 (which Electron 40 is based on), so I'll backport the patches to Electron 40, too. (And then I'll also do
main, because why not?)nikwen commentedon Feb 16, 2026
Two separate bugs were reported in this GitHub issue:
I will not get to work on the first one immediately. So I'll unassign myself from this issue for now.