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

can't get template ref when use dynamic component #4891

Closed
coader opened this issue Nov 3, 2021 · 11 comments
Closed

can't get template ref when use dynamic component #4891

coader opened this issue Nov 3, 2021 · 11 comments

Comments

@coader
Copy link

coader commented Nov 3, 2021

Version

3.2.21

Reproduction link

sfc.vuejs.org/

Steps to reproduce

click and will call child component's method

What is expected?

get dynamic instance with template ref

What is actually happening?

template ref return unexpected value:
comRef.value.test is not a function

@edison1105
Copy link
Member

edison1105 commented Nov 3, 2021

@languanghao
Copy link

languanghao commented Nov 8, 2021

@edison1105 I also find this problem in 'product' mode, but everything works fine in 'dev' mode.

From chrome F12, we can find rv.value has different value

product mode, need call rv.value._.exposed.handleConfirm()
image

dev mode, just call rv.value.handleConfirm()
image

@edison1105
Copy link
Member

@languanghao I will check it later.

@edison1105
Copy link
Member

@languanghao
I have done a test and it works fine in a production environment. Could you provide a demo with the problem?

@languanghao
Copy link

@edison1105
I try to write a samll demo to reproduce but failed. Maybe I can send you my product url ? Please tell me your email.

PS: 看地区你也是中国的,用中文交流可以吗?

@edison1105
Copy link
Member

@languanghao
Copy link

@edison1105 I can reproduce the bug.

When the dyanmic component ref to a component with top level await, the ref will get incorrect value.

Maybe the bug is here

const refValue = vnode.shapeFlag & 4
  /* STATEFUL_COMPONENT */
  ? getExposeProxy(vnode.component) || vnode.component.proxy : vnode.el;

When a component with top level await, getExposeProxy will return undefined

demo: https://github.com/languanghao/dymaic-ref

@edison1105
Copy link
Member

@languanghao thanks for your demo and I made a online demo
should be a bug.

@edison1105
Copy link
Member

@languanghao there is a workaround, see #4930 (comment)

@languanghao
Copy link

@edison1105 thank you, I will try it.

@WormGirl
Copy link

WormGirl commented Mar 15, 2022

see https://v3.vuejs.org/api/sfc-script-setup.html#defineexpose

demo

this demo at develepment env with options api can get ref, just at setup not work, but at production all work fine. why?

 "dependencies": {
    "@ant-design/icons-vue": "^6.0.1",
    "@vueuse/core": "^7.4.1",
    "ant-design-vue": "^3.0.0-alpha.12",
    "axios": "^0.24.0",
    "core-js": "^3.8.3",
    "vue": "^3.2.26",
    "vue-clipboard3": "^1.0.1",
    "vue-i18n": "^9.1.9",
    "vue-router": "4",
    "vue-shadow-dom": "^3.0.1",
    "vuedraggable": "^4.1.0"
  },
  "devDependencies": {
    "@types/jest": "^27.0.1",
    "@typescript-eslint/eslint-plugin": "^5.4.0",
    "@typescript-eslint/parser": "^5.4.0",
    "@vue/babel-plugin-jsx": "^1.1.1",
    "@vue/cli-plugin-babel": "~5.0.1",
    "@vue/cli-plugin-eslint": "~5.0.1",
    "@vue/cli-plugin-typescript": "~5.0.1",
    "@vue/cli-plugin-unit-jest": "~5.0.1",
    "@vue/cli-service": "~5.0.1",
    "@vue/eslint-config-prettier": "^6.0.0",
    "@vue/eslint-config-typescript": "^9.1.0",
    "@vue/test-utils": "^2.0.0-0",
    "@vue/vue3-jest": "^27.0.0-alpha.1",
    "babel-jest": "^27.0.6",
    "babel-plugin-import": "^1.13.3",
    "eslint": "^7.32.0",
    "eslint-config-prettier": "^8.3.0",
    "eslint-config-standard": "^16.0.3",
    "eslint-plugin-prettier": "^4.0.0",
    "eslint-plugin-vue": "^8.0.3",
    "jest": "^27.1.0",
    "less": "^4.1.2",
    "less-loader": "^10.2.0",
    "patch-package": "^6.4.7",
    "prettier": "^2.4.1",
    "sass": "^1.32.7",
    "sass-loader": "^12.0.0",
    "ts-jest": "^27.0.4",
    "typescript": "~4.5.5"
  }

@github-actions github-actions bot locked and limited conversation to collaborators Oct 1, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants