angular-ui / ui-router

The de-facto solution to flexible routing with nested views in AngularJS
http://ui-router.github.io/
MIT License
13.54k stars 3k forks source link

One Browser tab accessed 2nd Broswer tab $scope, using ui-routes and child states. #3580

Closed Vaaceph closed 6 years ago

Vaaceph commented 6 years ago

This is a:

My version of UI-Router is: (version) 0.3.1

Bug Report

Current Behavior:

It is one time issue occurred, I am unable to reproduce it. Let me first explain my project structure. My angularjs project have a parent state and it have 5 child routes. e.g.

Parent -> Step1 -> Step2 -> Step3 -> Step4 -> Step5.

and this hierarchy is strictly followed, it means that Step1 cant go to step5 direct. I am using $state.go to nagivate to next child state.

The Issue that occurred is that, if you open two tabs simultaneously on same browser for same parent state, in this example is Parent. Now, I use 2nd opened tab, and nagivate to Step1 then Step2, then Step3, then Step4 and to Step5. Everything was okay till Step4, and Step5 had been navigated successfully as well, but on Step5 there is an API Call to my server and on server I received data of 1st opened tab of browser,which is issue here. This data is set in $scope. And I am using $http service to send asynchronous call to my server.

Expected Behavior:

$scope is different for different tabs. so $scope.data1 should not be cross accessed in tabs.

Link to Plunker that reproduces the issue:

Unable to reproduce it again. I tried this.

General Query

Broswers:

It occurred on Safari 10.1 and it only occurred once. I have tried this to reproduce on Google Chrome Version 63.0.3239.84 and Safari 10.1

christopherthielen commented 6 years ago

Thanks for the nice bug report!

$scope is different for different tabs. so $scope.data1 should not be cross accessed in tabs.

Based on your description, this is definitely not a ui-router bug. It is simply not possible to share $scope across tabs. Each tab gets its own entire javascript runtime including separate angular runtimes, ui-router instances, and $scope trees.

Some possible things to check:

I can say with extreme confidence that this isn't a ui-router bug. Unfortunately, I can't tell where the problem indeed lies, except that I highly suspect your async calls to the server are the problem.