diff options
author | Kristóf Marussy <kristof@marussy.com> | 2022-06-20 01:03:18 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-06-19 23:03:18 +0000 |
commit | 9e69187c8c4b018f838d42cb6ebbf900c0cb2eb6 (patch) | |
tree | 10c2f2a3187effb454ab49a2da874c4df71ccff7 /src/components | |
parent | Fix version and add name to step on reddit action (diff) | |
download | ferdium-app-9e69187c8c4b018f838d42cb6ebbf900c0cb2eb6.tar.gz ferdium-app-9e69187c8c4b018f838d42cb6ebbf900c0cb2eb6.tar.zst ferdium-app-9e69187c8c4b018f838d42cb6ebbf900c0cb2eb6.zip |
fix: webview did-attach race condition (#302)
Make sure the event handler for attached webviews runs in a separate
task to avoid race conditions like
https://github.com/electron/electron/issues/31918
This should hopefully fix #157
Signed-off-by: Kristóf Marussy <kristof@marussy.com>
Diffstat (limited to 'src/components')
-rw-r--r-- | src/components/services/content/ServiceWebview.js | 16 |
1 files changed, 12 insertions, 4 deletions
diff --git a/src/components/services/content/ServiceWebview.js b/src/components/services/content/ServiceWebview.js index 6d6089793..66dc8af41 100644 --- a/src/components/services/content/ServiceWebview.js +++ b/src/components/services/content/ServiceWebview.js | |||
@@ -95,10 +95,18 @@ class ServiceWebview extends Component { | |||
95 | preload={preloadScript} | 95 | preload={preloadScript} |
96 | partition={service.partition} | 96 | partition={service.partition} |
97 | onDidAttach={() => { | 97 | onDidAttach={() => { |
98 | setWebviewReference({ | 98 | // Force the event handler to run in a new task. |
99 | serviceId: service.id, | 99 | // This resolves a race condition when the `did-attach` is called, |
100 | webview: this.webview.view, | 100 | // but the webview is not attached to the DOM yet: |
101 | }); | 101 | // https://github.com/electron/electron/issues/31918 |
102 | // This prevents us from immediately attaching listeners such as `did-stop-load`: | ||
103 | // https://github.com/ferdium/ferdium-app/issues/157 | ||
104 | setTimeout(() => { | ||
105 | setWebviewReference({ | ||
106 | serviceId: service.id, | ||
107 | webview: this.webview.view, | ||
108 | }); | ||
109 | }, 0); | ||
102 | }} | 110 | }} |
103 | onUpdateTargetUrl={this.updateTargetUrl} | 111 | onUpdateTargetUrl={this.updateTargetUrl} |
104 | useragent={service.userAgent} | 112 | useragent={service.userAgent} |