Skip to content

Commit 2d933e0

Browse files
committed
init/instance: fix NW.js window initialization
Resolves #911 Don't call `requestAnimationFrame` while the application window is still hidden during initialization. NW.js sometimes doesn't execute the animation frame callback during the initial window visibility state. This became clear after the NW.js 0.68.1 upgrade recently, which lead to the initialization never completing in certain cases on some systems. Remove the two `requestAnimationFrame` calls and schedule the `afterRender` Ember run-loop callback in the next run-loop, which ensures that the DOM is actually fully loaded and rendered by NW.js, so that no white screen appears for a few frames, which needs to be avoided when using the dark theme.
1 parent a285b9d commit 2d933e0

File tree

1 file changed

+6
-7
lines changed

1 file changed

+6
-7
lines changed

src/app/init/instance-initializers/nwjs/instance-initializer.js

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { get } from "@ember/object";
22
import { addObserver } from "@ember/object/observers";
3-
import { scheduleOnce } from "@ember/runloop";
3+
import { later, scheduleOnce } from "@ember/runloop";
44
import { default as nwApp, quit } from "nwjs/App";
55
import { default as nwWindow, setVisibility, setFocused } from "nwjs/Window";
66
import { argv, parseCommand } from "nwjs/argv";
@@ -52,12 +52,11 @@ export default {
5252
// restore window position first (while being hidden)
5353
await windowInitializer( application );
5454

55-
// wait until Ember has rendered the app for the first time (window is still hidden)
56-
await new Promise( resolve => scheduleOnce( "afterRender", resolve ) );
57-
// assume that NW.js doesn't render a white page anymore after the next two frames
58-
for ( let i = 0; i < 2; i++ ) {
59-
await new Promise( resolve => requestAnimationFrame( resolve ) );
60-
}
55+
// Wait until Ember has rendered the app for the first time (window is still hidden).
56+
// Wrap scheduled "afterRender" run-loop queue callback in a new run-loop to ensure
57+
// that the DOM is fully rendered and no white screen will appear for a few frames.
58+
// We can't use requestAnimationFrame here due to issue #911.
59+
await new Promise( resolve => later( () => scheduleOnce( "afterRender", resolve ) ) );
6160

6261
// wait until the target route is loaded
6362
const routeName = await routingPromise;

0 commit comments

Comments
 (0)