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

Adding 'ref' attribute to component in router-view breaks beforeRouteEnter next( vm => {} ) #461

Closed
AgileInteractive opened this issue Sep 8, 2020 · 4 comments
Labels
bug Something isn't working external This depends on an external dependency but is kept opened to track it

Comments

@AgileInteractive
Copy link

AgileInteractive commented Sep 8, 2020

Version

4.0.0-beta.9

Reproduction link

https://jsfiddle.net/1e9mqocg/1/

Steps to reproduce

Add router-view with transition

<router-view v-slot="{ Component }">
  <transition v-on:enter="enterTransition">
    <component :is="Component" ref="myRouteComponent"/>
  </transition>
</router-view>

Add beforeRouteEnter guard to child view

beforeRouteEnter(to, from, next) {
    console.log('* beforeRouteEnter');
    next((vm) => { vm.setData(); } );
},

methods: {
    setData() {
        console.log('*** "Set data" from beforeRouteEnter here');
    }
}

What is expected?

setData() to be called when clicking "Home" (inspect console.log)

What is actually happening?

setData is never called


Just deleting the 'ref' attribute makes it work again, but the ref attribute is very useful.

@posva
Copy link
Member

posva commented Sep 8, 2020

I think this one is a bug on vue. I will try to create a repro in the following days. The problem is we use our own ref to retrieve the component instance but it gets overriden by the user's.
If you want to try to reproduce it in Vue. The relevant code is in RouterView

setup(props, { slots }) {
return () => {
      const component = h(
        ViewComponent,
        {
          ref: viewRef, // a ref()
        }
      )

  return slots.default({ Component: component })
  }
}

@posva
Copy link
Member

posva commented Sep 9, 2020

Opened vuejs/core#2078

@posva posva added has workaround A workaround has been found to deal with the issue bug Something isn't working external This depends on an external dependency but is kept opened to track it and removed has workaround A workaround has been found to deal with the issue labels Sep 11, 2020
@posva posva closed this as completed Sep 14, 2020
@posva
Copy link
Member

posva commented Sep 14, 2020

Fixed in vue-next

@posva
Copy link
Member

posva commented May 18, 2021

I don't know, the reproductions seem to work. A proper bug report would help

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working external This depends on an external dependency but is kept opened to track it
Projects
None yet
Development

No branches or pull requests

2 participants