Subscribe on changes!

inject/getCurrentInstance does not work with createVNode and render

avatar
Aug 22nd 2022

Vue version

3.2.37

Link to minimal reproduction

https://stackblitz.com/edit/vitejs-vite-7xsuzb

Steps to reproduce

From @vue/repl idea, I'm creating 1 live preview editor on 1 other storefront project. But when the code renders using createVNode and render, all values from getCurrentInstance are null. Please suggest me how to solve this problem. Thank you!

What is expected?

inject/getCurrentInstance values from app storefront project

What is actually happening?

inject/getCurrentInstance result is always null

System Info

Browsers

Any additional comments?

No response

avatar
Aug 22nd 2022
  1. using internals in this way is hacky and risks breaking in the future

  2. the reproduction doesn't demonstrate the problem described so I kinda need to guess.

  3. However I think your problem is that you have two projects, with two node_modules folders, each containing a copy of the vue package, and both are being included at one point. Assuming one is being built as a library and consumed in the other, you have to:

  4. in the library, make sure to externalize vue so it's not bundled with the library

  5. in the consuming app's vite config, add resolve: { dedupe: ['vue'] } to make vite get rid of duplicate package sources.

avatar
Aug 22nd 2022

@LinusBorg Thank you. If possible, can you suggest me how to replace createVNode and render?

avatar
Aug 22nd 2022

I'm not sure what you are asking.

You should direct support questions to this repo's discussions or our discord server