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

Auto-import seems to be not working inside functional components #5373

Closed
panstromek opened this issue Oct 22, 2019 · 4 comments
Closed

Auto-import seems to be not working inside functional components #5373

panstromek opened this issue Oct 22, 2019 · 4 comments

Comments

@panstromek
Copy link
Contributor

panstromek commented Oct 22, 2019

Describe the bug
When I use quasar component inside functional component, using auto-import feature, I get

Unknown custom element: <q-icon> - did you register the component correctly? For recursive components, make sure to provide the "name" option.

To Reproduce

  1. Start new project
  2. Create functional component inside it
<template functional>
  <div>
    <q-icon name="warning" />
  </div>
</template>
<script>
export default {
  name: 'FunctionalComponent'
}
</script>
  1. Use it on some page
@huy-tran
Copy link
Contributor

https://quasar.dev/quasar-cli/quasar-conf-js#Property%3A-framework

Did you try to have "framework": { "all": "auto" } in quasar.conf.js file ?

@nothingismagick
Copy link
Contributor

I'm seeing similar in components from app extensions. Even if I manually add them to the boot-file in the index.js rigger, when combined with auto in the consuming quasar.conf.js, they are not hooked. It would probably make sense to merge auto with whatever is manually configured. @webnoob

@ejez
Copy link
Contributor

ejez commented Nov 17, 2019

Quasar auto-import loader automatically adds the detected components in the components option of the component defined in a vue file, for the example given above, the following is automatically added:

import {QIcon} from 'quasar'
component.options.components = Object.assign({QIcon}, component.options.components || {})

Functional components however do not accept the components option, thus the following code added by quasar auto-import loader gets disregarded by Vue:

component.options.components = ...

We can't declare (locally register) vue components inside a functional component, this is by design. Why functional components do not accept components option? because they are simplified for performance and do not accept all the options normal (stateful) components do.
See: vuejs/vue#8287 (comment) (point n 4)

To be able to use a vue component inside a functional component you need to register it globally (not recommended) or use a workaround like: vuejs/vue#7492 (comment)

Now for the auto import feature, the auto-import loader can be modified to detect a functional component, and instead of adding component.options.components = Object.assign({QIcon}, component.options.components || {}) , it adds the global registration Vue.component("q-icon", QIcon), but I think it is not worth it especially with the upcoming Vue 3 (see link above)

In any case this is a bug, and quasar should not add extra code that gets disregarded (assigning to components option in a functional component)

rstoenescu pushed a commit that referenced this issue Nov 18, 2019
* fix(webpack): auto-import loader

auto-import loader should not process functional components

See #5373

* Update loader.auto-import.js

* Update loader.auto-import.js
@rstoenescu
Copy link
Member

Thank you for the write-up @ejez ! It's 100% accurate.

mesqueeb pushed a commit to mesqueeb/quasar that referenced this issue Feb 2, 2020
* fix(webpack): auto-import loader

auto-import loader should not process functional components

See quasarframework#5373

* Update loader.auto-import.js

* Update loader.auto-import.js
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

5 participants