mirror of
https://github.com/wailsapp/wails.git
synced 2026-03-14 14:45:49 +01:00
fix(v3): guard dispatchWailsEvent against race condition on reload (#4925)
* fix(v3): guard dispatchWailsEvent against race condition on reload When the page is reloaded, the WindowLoadFinished event can fire before the JavaScript runtime has mounted dispatchWailsEvent on window._wails. This causes a TypeError: window._wails.dispatchWailsEvent is not a function. This fix adds a guard to check if window._wails and dispatchWailsEvent exist before attempting to call the function. If the runtime isn't ready, the event is silently skipped (which is correct since there's no handler). Fixes #4872 Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com> * docs: Add changelog entry for #4872 --------- Co-authored-by: ddmoney420 <ddmoney420@users.noreply.github.com> Co-authored-by: Claude Opus 4.5 <noreply@anthropic.com> Co-authored-by: Lea Anthony <lea.anthony@gmail.com>
This commit is contained in:
parent
8b99993faa
commit
5d0dd30685
1 changed files with 4 additions and 1 deletions
|
|
@ -1180,7 +1180,10 @@ func (w *WebviewWindow) SetFrameless(frameless bool) Window {
|
|||
}
|
||||
|
||||
func (w *WebviewWindow) DispatchWailsEvent(event *CustomEvent) {
|
||||
msg := fmt.Sprintf("window._wails.dispatchWailsEvent(%s);", event.ToJSON())
|
||||
// Guard against race condition where event fires before runtime is initialized
|
||||
// This can happen during page reload when WindowLoadFinished fires before
|
||||
// the JavaScript runtime has mounted dispatchWailsEvent on window._wails
|
||||
msg := fmt.Sprintf("if(window._wails&&window._wails.dispatchWailsEvent){window._wails.dispatchWailsEvent(%s);}", event.ToJSON())
|
||||
w.ExecJS(msg)
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue