Changes to the DOM between alert boxes
Reported by
m...@codeavengers.com,
Aug 19 2016
|
|||||
Issue descriptionChrome Version : 52.0.2743.116 m URLs (if applicable) : https://www.codeavengers.com/c/mike/chrome-bug.html Other browsers tested: Safari: Firefox: OK 46.0.1 IE: OK 11.545.10586.0 EDGE: OK 25.10586.0.0 What steps will reproduce the problem? (1) Run the example url to demonstrate the problem. It contains the following JavaScript code. alert('When you click OK, the screen should go red immediately.') document.body.style.backgroundColor = 'red' alert('If you are in firefox or edge the background will be red. If you are in Chrome the background will be white until you close this alert box') What is the expected result? After the first alert is displayed, and the user clicks OK, the screen shot change to red immediately, before the 2nd alert is displayed. What happens instead? The screen remains white until the 2nd alert box is closed. Please provide any additional information below. Attach a screenshot if possible.
,
Aug 22 2016
,
Aug 22 2016
,
Aug 24 2016
aelias@, is this working as intended? FYI, safari shows the same behavior as we do.
,
Aug 24 2016
Yes, this seems like the expected behavior. alert is immediately blocking whereas painting posts asynchronous tasks, and we intentionally changed not to run any tasks on the main message loop while the alert is active.
,
Aug 24 2016
This change is documented at https://www.chromestatus.com/features/5683408571203584 , for reference.
,
Aug 24 2016
Drat!!!! I'd developed a bunch of online JavaScript projects that relied on printing messages to a console in between alert boxes appearing... going to be a real pain to change all those lessons. For now we've just had to tell people to use Firefox or Edge. I guess that's the risk you take with web development!!
,
Aug 24 2016
It also broke our python course that uses Brython, which implements input using prompts... and print by printing to the console. We try to display console messages in an element on the webpage... but they won't display in between prompt messages. I guess the only work around for this is to tell people they have to use Firefox? Since completely rewriting our Python courses is not really an option at this stage.
,
Aug 24 2016
So what is the rationale behind having an alert box blocking changes to the dom that occurred on the previous line of code?
,
Aug 24 2016
Sorry, I realize the behavior is surprising -- the root cause is that alert() is an odd duck in the web platform to begin with. The rationale is the portion of the spec about event loops: https://html.spec.whatwg.org/multipage/webappapis.html#event-loop . When you modify the DOM, although the change to the DOM itself is instantaneous, actually painting it to the screen is posted as a task/microtask on the loop to be run after your JS yields. This is an essential optimization to avoid multiple paint passes when JS touches a lot of DOM at once, shared among all browsers. What changed in Chrome M52 is that alert(), which is a immediately run "paused task", now better conforms to the spec text: "While a user agent has a paused task, the corresponding event loop must not run further tasks, and any script in the currently running task must block." On Firefox, IE and Chrome <=51, there is a special "nested event loop" that runs more tasks inside paused tasks, which we removed. This conforms with Safari's behavior and other browser vendors may eventually also follow. Anyway, I'm sorry we broke your online course with this change. A workaround to keep using Chrome would be to post messages using "console.log()" and ask your students to use Chrome developer tools "Console" instead of your custom display. Note that this workaround would also be needed for Safari. I'd understand if you don't consider this satisfactory and prefer to recommend Firefox, though.
,
Aug 24 2016
Another easy workaround for alert() and prompt() in this case is to use modal dialog such as this: http://jqueryui.com/dialog/#modal
,
Aug 24 2016
Right, although such alert polyfills are nonblocking, so they might not be satisfactory if the intent is to interrupt the JS execution for instructional purposes. The ideal solution would be to use such a polyfill in combination ES7 async await, although that's very cutting edge for now (only implemented by Chrome 53 behind --enable-experimental-web-platform-features flag: see https://www.chromestatus.com/feature/5643236399906816 ).
,
Aug 24 2016
Yeah, the lessons rely on the blocking functionality. I am eagerly awaiting await... as that will be a good solution... A shame about the timing of this change! The first of the courses have been around for almost 5 years without issue on Chrome, FF, IE, Edge... Does anyone have any idea when await will be available without the experimental flag?? Once that's available, we can use that for Chrome, and keep the existing approach in FF, IE, Edge. Mike
,
Aug 24 2016
And thanks so much for the detailed replies! I wasn't expecting such helpful responses!
,
Aug 25 2016
Sure, explaining the reason is the least we can do. > Does anyone have any idea when await will be available without the experimental flag?? There's no predetermined schedule, the only answer I can give is "when it's finished". You can follow the progress on https://bugs.chromium.org/p/v8/issues/detail?id=4483 and https://www.chromestatus.com/feature/5643236399906816
,
Sep 19 2016
Issue 648206 has been merged into this issue. |
|||||
►
Sign in to add a comment |
|||||
Comment 1 by tkonch...@chromium.org
, Aug 19 2016Components: Blink
Labels: -Type-Bug -Pri-3 M-54 OS-Linux OS-Mac OS-Windows Pri-2 Type-Bug-Regression
Owner: changwan@chromium.org
Status: Assigned (was: Unconfirmed)