-
-
Notifications
You must be signed in to change notification settings - Fork 8.2k
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
Prevent self inject #1818
Comments
Can you provide a boiled down repro? |
Turns out injection hook is called before provide, so it is not possible to self-inject. Sorry for the inconvenience. |
Sign up for free
to subscribe to this conversation on GitHub.
Already have an account?
Sign in.
What problem does this feature solve?
There's a problem with current provide\inject behaviour when component provides the same key it injects. If you try to do that you'll inject the same value that is provided by the component. The problem with that is that it's impossible to override provisions in a single component, which makes nested provisions unnecessary complicated. In order to do that you'll have to split provide\inject into two components and somehow share or even duplicate data between these two components (usually by manually cycling through
this.$parent
chain).A common example of deep provision are breadcrumbs:
This provision could be used on nested page components to automatically generate components for each route level.
The code above obviously doesn't work because injected and provided
breadcrumbs
would be equal.It's also unclear for me what's the use-case for self-injection. If there's not such case I think self-injection can be safely prevented and at the same time open opportunities for cleaner provide\inject techniques.
What does the proposed API look like?
The suggestion is that self-injection should be prevented by default.
The text was updated successfully, but these errors were encountered: