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

Got error "Error: useComputedClass must be called within a component setup function." #709

Closed
Tracked by #245
isamu opened this issue Jan 1, 2024 · 8 comments · Fixed by #725
Closed
Tracked by #245
Assignees
Labels
bug Something isn't working

Comments

@isamu
Copy link

isamu commented Jan 1, 2024

Overview of the problem

Oruga version: [0.8.1]
Vuejs version: [3.4]
OS/Browser:
Mac/Chrome

Description

When using o-field tag, I see an error.

useComputedClass.ts:57 Uncaught (in promise) Error: useComputedClass must be called within a component setup function.
    at useComputedClass(useComputedClass.ts:57:15)
    at Field.vue:235:5

It worked fine until 0.8.0, but an error occurs with 0.8.1 and 0.8.2.

Steps to reproduce

Reproduce with the following tag from the official document.

  <section>                                                                                                                                                      
    <o-field label="Name">                                                                                                                                       
        <o-input model-value="Kevin Garvey" />                                                                                                                   
    </o-field>                                                                                                                                                   
  </section> 

Expected behavior

No error occurs

Actual behavior

Got Error

isamu added a commit to Nakajima-Foundation/ownplate that referenced this issue Jan 1, 2024
@jtommy
Copy link
Member

jtommy commented Jan 2, 2024

Probably it's a issue with last version of Vue (3.4), you should be able to use last oruga version with Vue 3.3

@isamu
Copy link
Author

isamu commented Jan 2, 2024

When I changed from vue-cli-service to vite, and changed from vue3.3 to 3.4, this problem occurred.
To investigate the problem, I created a new environment using npm create vite@latest and npm create vue@latest, set it up according to oruga's readme, and tested it.

As a result, the Vue version had no effect, and the error occurred only when the oruga version was changed from 0.8.0 to 0.8.1.

@isamu
Copy link
Author

isamu commented Jan 2, 2024

( #710 is another problem I found during that investigation.)

@isamu
Copy link
Author

isamu commented Jan 2, 2024

Sorry.
I checked again in my package.json

"vue": "^3.3.11"

So, 3.4 was installed.
This is a problem with 3.4.

@jtommy jtommy added the bug Something isn't working label Jan 2, 2024
@digital-codes
Copy link

probably same as this one from vue: vuejs/core#9974

@mlmoravek
Copy link
Member

Hi @digital-codes, thanks for the link. I think the discussion seems very related to this issue. This also helps to understand the problem. My opinion is to wait some time and see how this discussion develops. Otherwise I might have an idea how to refactor the Oruga codebase to maybe prevent this.

@digital-codes
Copy link

digital-codes commented Jan 4, 2024

I tried to do some debugging ... not really successfull. However, in the context of the error I get this output:
// checking of if the function exists, just to be sure
getcurins function: function getCurrentInstance()
useComputedClass.ts:56:12

// checking return from function. is null (well, we knew that already, 99.9%)
getcurins function returned: null
useComputedClass.ts:58:12

Here comes the error. Note, I've replace the exception with a console.log ...
!!!! useComputedClass must be called within a component setup function.!!!
useComputedClass.ts:60:16

Then there is a warning from vue, which might or might not be related.
[Vue warn]: Unhandled error during execution of scheduler flush. This is likely a Vue internals bug. Please open an issue at https://github.com/vuejs/core . runtime-core.esm-bundler.js:39:12

// this is probably an artifact from not throwing the exception ....
Uncaught (in promise) TypeError: vm is null
useComputedClass useComputedClass.ts:67
draggableClasses Upload.vue:251

Finally a warning from Oruga, which might be a result again from the missing exception ...
Underlaying Oruga input component not found
useInputHandler.ts:73:20

Maybe this helps at least a bit

@mlmoravek
Copy link
Member

Just to be transparent; I've started on a refactoring for the classes properties.
My approach will be to refactor from computed to a ref with a watcher.

Before:

const rootClasses = computed(() => [
    useComputedClass("rootClass", "o-btn"),
    {
        [useComputedClass("sizeClass", "o-btn--", props.size)]: props.size,
    },
    ...
]);

To something like:

const rootClasses = defineClasses([["rootClass", "o-btn"], ["sizeClass", "o-btn--", props.size, !!props.size], ...]);

The defineClasses will return a ref value. Within the defineClasses composable, the useComputedClass composable is triggered only once on setup time. After that, the computed classes are applied to or removed from the ref object by a watcher.

Disclaimer: These are early thoughts and experiments, not the final solution yet.

lgedgar added a commit to lgedgar/q-apps-dev-sandbox that referenced this issue Jan 20, 2024
b/c i was getting an error with 3.4.x as described in
oruga-ui/oruga#709
QcumberCumquat pushed a commit to QcumberCumquat/Timely that referenced this issue Jan 31, 2024
Because of issues like oruga-ui/oruga#709

Signed-off-by: Thomas Citharel <tcit@tcit.fr>
tcitworld added a commit to framasoft/mobilizon that referenced this issue Feb 8, 2024
Because of issues like oruga-ui/oruga#709

Signed-off-by: Thomas Citharel <tcit@tcit.fr>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants