dart-lang / sdk

The Dart SDK, including the VM, JS and Wasm compilers, analysis, core libraries, and more.
https://dart.dev
BSD 3-Clause "New" or "Revised" License
10.07k stars 1.56k forks source link

Clicking the back button in Dartium sometimes causes Dart to run two separate DOM isolates on the same page #10949

Closed jacob314 closed 9 years ago

jacob314 commented 11 years ago

Clicking the back button in Dartium sometimes causes Dartium to run two separate DOM isolates for the same .dart code causing the page to render incorrectly unless hacky code like the following is added. The issue only occurs when you open a page containing Dart, navigate to a link on a different domain, then click the back arrow to reopen the page. Reloading a page or opening the page fresh will not trigger the issue.

Note: clicking the back arrow by design behaves differently than reloading the page. For example, scripts aren't reloaded, etc. As far as I know, the issue only reproduces reliably on large applications where perhaps there are browser memory leaks due to lots of event listeners attached to the DOM.

Here is the code I use add to workaround the issue.

  // This is a workaround for a bug where an isolate is loaded twice when the back button is pressed. main() {   if (document.documentElement.dataset.containsKey('dart-loaded')) {     throw "Skipping main as Dart is already loaded. This is due to a Dartium bug";   }   document.documentElement.dataset['dart-loaded'] = "true";

  // Run actual main code.... }

jacob314 commented 11 years ago

Added Triaged label.

sigmundch commented 11 years ago

Ok, following along a test case Jacob had, we created this smaller repro of some of the bug/problems.

to repro: put all the 3 files in the same dir, then open index.html in dartium. Click on "move away" then click the back button, look at the output printed in the console.

Some interesting things:


Attachments: other.dart (31 Bytes) index.html (235 Bytes) isolate_bug.dart (197 Bytes)

jacob314 commented 11 years ago

Changed priority to medium as we don't need to run multiple DOM isolates each in their own script tags in the near future so this bug won't be an immediate blocker.


Removed Priority-High label. Added Priority-Medium label.

DartBot commented 11 years ago

This comment was originally written by antonm@google.com


That's an abuse of Dart's DOM app model.

As of now adding dart scripts on the fly have undefined behaviour. For example, if you add it late enough, those scripts won't be executed.

Technically right now NodeList of script elements was used, and this node list is live, so if you modify it on the fly via script elements insertion, you've got this behaviour.

To make this behaviour more robust at least I'm adding snapshotting of the list script tags found when about to start dart isolates: at least we should have consistent behaviour.


Added this to the M5 milestone. Added AsDesigned label.