Skip to content

Provide / Inject issues with custom elements and inserting raw html  #5096

Closed
@Rkaede

Description

@Rkaede

Version

3.2.26

Reproduction link

stackblitz.com

Steps to reproduce

View the output in the repo to see that the second example of my-component is not displaying the injected value from provide-a. It only displays the provide value from the closest element.

What is expected?

In the provided repo there are 3 custom elements created with vue. 2 of the elements provide a value and injects both of them.

If the custom elements are used within a vue component template then my-component has access to both the provided values from provide-a and provide-b. If the custom elements are inserted through <div v-html="myHtml"></div> or directly through innerHTML the same behaviour is expected.

What is actually happening?

Only the closest provide value from provide-b is available to the my-component. The value from provide-a is not available.


The use case for this is loading html (with custom elements) from a server as a string and inserting it into the page.

Activity

Rkaede

Rkaede commented on Dec 12, 2021

@Rkaede
Author

As a workaround for any components that provide a value I relay any parent values through a context object.

// provide-b composition api example
setup(props) {
  const context = inject('context', {});
  provide('context', { ...context, b: props.b });
}
self-assigned this
on Dec 13, 2021
added a commit that references this issue on Nov 11, 2022
192dcb6
added a commit that references this issue on Feb 4, 2023
4c30237
added a commit that references this issue on Apr 12, 2023
6eff5a8
locked and limited conversation to collaborators on Sep 18, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

    Participants

    @LinusBorg@Rkaede

    Issue actions

      Provide / Inject issues with custom elements and inserting raw html · Issue #5096 · vuejs/core