Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

beforeRouteEnter hook's next callback invoked with wrong instance #1874

Closed
nirazul opened this issue Nov 9, 2017 · 8 comments
Closed

beforeRouteEnter hook's next callback invoked with wrong instance #1874

nirazul opened this issue Nov 9, 2017 · 8 comments
Labels

Comments

@nirazul
Copy link

nirazul commented Nov 9, 2017

Version

3.0.1

Reproduction link

https://codepen.io/Nirazul/pen/GOrjVW?editors=1010

Steps to reproduce

Follow these instructions to reproduce the issue:

  1. Click on "Baz"
  2. Click on "Bar"
  3. Click on "Foo"
  4. Click on "Baz" again

You should see that "$data" is empty.

It doesn't matter where you start as long as you follow the above order at some point. The behaviour is normal, when you leave out the second or third step.

What is expected?

The route succeeds in fetching the correct data in any order of navigation.

What is actually happening?

When I follow the pages in the order described in the reproduction steps section, the router fails to load one of the pages.


It most definitely has something to do with the transition mode "out-in". When I remove the attribute or use "in-out", everything seems to work normally.

@LinusBorg
Copy link
Member

Certainly something top investigate - in the meantime, applying a key to the router-view make it work again:

<router-view :key="$route.path"></router-view>

Definitely has something to do with the transition, but I can't say what for the moment.

@nirazul
Copy link
Author

nirazul commented Nov 9, 2017

@LinusBorg: Thanks for the quick answer! Unfortunately, $route.path turns out to break some other part of our app (when we have route pathes with params in them). I've changed it to route specific property in meta, which seems to work for both cases.

@PeachScript
Copy link
Contributor

@LinusBorg I have the same problem, is there any update?

@LinusBorg
Copy link
Member

You would read about it here if there was.

@PeachScript
Copy link
Contributor

PeachScript commented Mar 16, 2018

I also created a live demo: https://jsfiddle.net/hj1pbgfw/2/ , when I using transition with out-in mode, after 4 steps, I found 3 problems:

  1. The mounted will be invoke after the next function from beforeRouteUpdate
  2. The next function frombeforeRouteUpdate will get a destroyed instance and different with mounted gets
  3. The destroyed instance still working, that means, if you listen instance event or bind element event in the instance, it will be triggered multiple times, because there has multiple same instances

@PeachScript
Copy link
Contributor

@LinusBorg thanks for your quick reply, do you planning to fix it?

@LinusBorg
Copy link
Member

Sure, when someone finds time to pick up the task. I won't as I don't know the internals that are involved well enough to debug it in a reasonable timeframe.

@PeachScript
Copy link
Contributor

Well, 4 months have passed, I will make a PR if I can fix it, thanks.

PeachScript pushed a commit to PeachScript/vue-router that referenced this issue Mar 26, 2018
PeachScript added a commit to PeachScript/vue-router that referenced this issue Mar 26, 2018
@posva posva added the bug label Mar 26, 2018
posva pushed a commit that referenced this issue Jul 2, 2018
**What kind of change does this PR introduce?** (check at least one)

- [x] Bugfix
- [ ] Feature
- [ ] Code style update
- [ ] Refactor
- [ ] Build-related changes
- [ ] Other, please describe:

**Does this PR introduce a breaking change?** (check one)

- [ ] Yes
- [x] No

If yes, please describe the impact and migration path for existing applications:

**The PR fulfills these requirements:**

- [x] It's submitted to the `dev` branch for v2.x (or to a previous version branch), _not_ the `master` branch
- [x] When resolving a specific issue, it's referenced in the PR's title (e.g. `fix #xxx[,#xxx]`, where "xxx" is the issue number)
- [x] All tests are passing: https://github.com/vuejs/vue/blob/dev/.github/CONTRIBUTING.md#development-setup
- [ ] New/updated tests are included

If adding a **new feature**, the PR's description includes:
- [ ] A convincing reason for adding this feature (to avoid wasting your time, it's best to open a suggestion issue first and wait for approval before working on it)

**Other information:**

This is a PR for #1874 , cc: @LinusBorg
@posva posva closed this as completed Jul 9, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

4 participants