Skip to content

runWithContext cannot self-boot #13256

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

Closed
leookun opened this issue Apr 29, 2025 · 2 comments
Closed

runWithContext cannot self-boot #13256

leookun opened this issue Apr 29, 2025 · 2 comments
Labels
need more info Further information is requested

Comments

@leookun
Copy link

leookun commented Apr 29, 2025

Vue version

3.5

Link to minimal reproduction

https://play.vuejs.org/#eNp9UcFuwjAM/ZUoF4qECtN2YhRpQxzYYZs2pF1yqYqBsNaJEochof77nDBGD4hDlPj5OX7PPsona/N9ADmWE185bUl4oGCnCnVjjSNxFBugWXAOkBboqcQKRCvWzjSix5U9hZVhXJTWiuIKOesr5D+XugETKMv6opiKo0IRK3I+M4MEB4rP3AX80rT9g7pkptfgKLvWQBRFEX/rP0ZmG692IO5Go1F8KpwMT97YFQcEja1LAo4mw04gB5I8e1nrTb7zBnkmqbOSlWms5u5vljR7VXJ81qRkWdfm5yVh5AIMzni1her7Cr7zh4gp+e7Ag9uDkv85Kh3bO6Xnn688gU6yMatQM/tG8gO8qUPUeKI9B1yx7A4vqV2kzWrcLP38QID+bCoKTRNMfCV5vbMb1i9y7/OHVMdzl+0v+wHHjA==

Steps to reproduce

const app = getCurrentInstance()
setTimeout(() => {
  app.appContext.app.runWithContext(() => {
    alert(getCurrentInstance() === app);
  });
}, 1000);

The above code always alerts false, ideally it should output true.

What is expected?

const app = getCurrentInstance()
setTimeout(() => {
  app.appContext.app.runWithContext(() => {
    alert(getCurrentInstance() === app);
  });
}, 1000);

The above code always alerts false, ideally it should output true.

What is actually happening?

getCurrentInstance should be running in an app context, like inject

runWithContext provides context to the function,In my scene, I cannot automatically pass context

Image

openDatasetSelect internally uses the render method to render the component into the body, and the component internally uses getCurrentInstance

System Info

System:
    OS: macOS 13.2.1
    CPU: (10) arm64 Apple M2 Pro
    Memory: 98.73 MB / 16.00 GB
    Shell: 5.8.1 - /bin/zsh
  Binaries:
    Node: 20.19.0 - /usr/local/bin/node
    Yarn: 1.22.19 - /usr/local/bin/yarn
    npm: 10.8.2 - /usr/local/bin/npm
    pnpm: 9.6.0 - ~/Library/pnpm/pnpm
    bun: 1.0.0 - ~/Library/pnpm/bun
  Browsers:
    Chrome: 135.0.7049.115
    Safari: 16.3

Any additional comments?

No response

@leookun
Copy link
Author

leookun commented Apr 29, 2025

The getCurrentInstance is not recommended for use. The fundamental issue is how to obtain the runWithContext again within the asynchronous function inside the runWithContext function?

Image

@edison1105
Copy link
Member

The minimal reproduction does not make sense to me.
Please provide a reproduction that closely matches your actual application.

@edison1105 edison1105 added the need more info Further information is requested label Apr 29, 2025
@leookun leookun closed this as completed Apr 30, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
need more info Further information is requested
Projects
None yet
Development

No branches or pull requests

2 participants