element-plus [Bug Report] [Component] [autocomplete] Use callback function of fetchSuggestions in ElAutocomplete gets exception

ykejflvf  于 2022-11-05  发布在  其他
关注(0)|答案(4)|浏览(225)

Bug Type:Component

Environment

  • Vue Version: 3.2.31
  • Element Plus Version: 2.1.10
  • Browser / OS: Chrome/100.0.4896.127 / Windows 10
  • Build Tool: Vue CLI

Reproduction

  • el-autocomplete

Element Plus Playground

Steps to reproduce

Click on the el-autocomplete component to get the exception from console.

It only happens when fetchSuggestions is an async function. Exception gets triggered by the code line:
element-plus/packages/components/autocomplete/src/autocomplete.vue

Line 189 in 5068528

| | result.then(cb) |

From the doc, fetched suggestions need to be committed via the callback function. But in the code of component el-autocomplete, the callback function gets invoked again after fetchSuggestions finished. Is it necessary?

const result = props.fetchSuggestions(queryString, cb);
if (isArray(result)) {
  cb(result)
} else if (isPromise(result)) {
  result.then(cb)
}

What is Expected?

Works without exception

What is actually happening?

Throw exceptions

Additional comments

  • (empty)*
bpzcxfmw

bpzcxfmw2#

playground
Maybe it should be written that way.

wgmfuz8q

wgmfuz8q3#

Yeah, this resolved the exception. I am thinking that, the cb will be invoked after fetch-suggestions , if we as the users invoked the cb as method parameter inside fetch-suggestions , that means in this case the cb will be invoked twice. Maybe this part can be improved?

yhived7q

yhived7q4#

Yeah, this resolved the exception. I am thinking that, the cb will be invoked after fetch-suggestions , if we as the users invoked the cb as method parameter inside fetch-suggestions , that means in this case the cb will be invoked twice. Maybe this part can be improved?

follow #7315

相关问题