fix(v3): guard dispatchWailsEvent against race condition on reload#4925
Conversation
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 wailsapp#4872 Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
|
Caution Review failedThe pull request is closed. WalkthroughGuards the runtime call to Changes
Estimated code review effort🎯 2 (Simple) | ⏱️ ~10 minutes Suggested labels
Poem
🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing touches
🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
|
Thanks 🙏 Please could you add an entry to the changelog located at |
Fix race condition causing TypeError during page reload. Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
|
Fix race condition causing TypeError during page reload. Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
…ailsapp#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 wailsapp#4872 Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com> * docs: Add changelog entry for wailsapp#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>



Summary
Guards
window._wails.dispatchWailsEventcalls against race conditions during page reload.Problem
When the page is reloaded, the
WindowLoadFinishedevent can fire before the JavaScript runtime has mounteddispatchWailsEventonwindow._wails. This causes:This is a classic race condition between:
WindowLoadFinishedevent immediatelySolution
Added a guard to check if
window._wailsanddispatchWailsEventexist before calling:If the runtime isn't ready, the event is silently skipped (correct behavior since there's no handler).
Test plan
wails3 devon a fresh projectFixes #4872
🤖 Generated with Claude Code
Summary by CodeRabbit
✏️ Tip: You can customize this high-level summary in your review settings.