Skip to content

fix: Activate event window creation awaits app ready state - #130

Merged
wojtekn merged 2 commits into
trunkfrom
fix/activate-event-window-creation-awaits-app-ready
May 15, 2024
Merged

fix: Activate event window creation awaits app ready state#130
wojtekn merged 2 commits into
trunkfrom
fix/activate-event-window-creation-awaits-app-ready

Conversation

@dcalhoun

@dcalhoun dcalhoun commented May 14, 2024

Copy link
Copy Markdown
Member

Fixes https://github.com/Automattic/dotcom-forge/issues/7158.

Proposed Changes

Await the app "ready" state before creating a window within the app "activate"
event handler.

Testing Instructions

Note

The test instructions are a contrived example as the original crash is the result of a race condition between the ready and activate event handler logic. The instructions rely upon intentionally creating a window within the will-finish-launching event handler, which is guaranteed to run before the ready event.

Contrived error diff
diff --git a/src/index.ts b/src/index.ts
index 692138e..95272a7 100644
--- a/src/index.ts
+++ b/src/index.ts
@@ -246,7 +246,7 @@ async function appBoot() {
 		stopAllServersOnQuit();
 	} );
 
-	app.on( 'activate', () => {
+	app.on( 'will-finish-launching', () => {
 		// On OS X it's common to re-create a window in the app when the
 		// dock icon is clicked and there are no other windows open.
 		if ( BrowserWindow.getAllWindows().length === 0 ) {
Example window error window-error
  1. Check out the trunk branch.
  2. Apply the provided diff (see above).
  3. Launch the app with npm start.
  4. Note the app launches with an error.
  5. Check out the proposed changes.
  6. Repeat steps 2-3.
  7. Verify the app launches without an error.

Pre-merge Checklist

  • Have you checked for TypeScript, React or other console errors?
Creating a window before the app is "ready" results in an error.
@dcalhoun dcalhoun self-assigned this May 14, 2024
Unlikely to occur, but likely still worth handling as we do not want to
start the user off with an error.
@dcalhoun
dcalhoun marked this pull request as ready for review May 14, 2024 17:05
@dcalhoun
dcalhoun requested review from a team May 14, 2024 17:05

@derekblank derekblank 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.

I was able to follow the testing steps successfully:

  • Observed the error on trunk, reproduced with the provided diff
  • Observed the error was not present on this PR branch with the diff still applied

LGTM. Thanks for adding tests as well. 🚀

@wojtekn wojtekn 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.

Looks good. Thanks for adding tests!

@wojtekn
wojtekn merged commit 63f8957 into trunk May 15, 2024
@wojtekn
wojtekn deleted the fix/activate-event-window-creation-awaits-app-ready branch May 15, 2024 08:11
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

3 participants