qwik icon indicating copy to clipboard operation
qwik copied to clipboard

[🐞] Error when including function within the store. Function is not serializable.

Open estebanpanelli opened this issue 3 years ago • 2 comments

Which component is affected?

Qwik Runtime

Describe the bug

I want to keep track of the user state with a store and a context defined in an AppProvider component.

AppProvider:

export const UserContext = createContextId<UserStore>("app.user-context");

export default component$( ...

    const Store = useStore({
        ...
       setName: $(function (this, name) { this.name = name }),
    })

    useVisibleTask$( onAuthStateChanged( Store, ...) )

    useContextProvider(UserContext, Store);

    return <Slot />
}

But when I include the setName function I get the following error:

Seems like you are referencing "Store" inside a different scope (useVisibleTask$), when this happens, Qwik needs to serialize the value, however "Store.setName" is a function, which is not serializable.

Check out https://qwik.builder.io/docs/advanced/dollar/ for more details.eslint[qwik/valid-lexical-scope](https://qwik.builder.io/docs/advanced/dollar/)

Reproduction

https://github.com/estebanpanelli/qwik-firebase-provider

Steps to reproduce

Optional include Firebase keys on app-providers.tsx

Run npm install & npm start

System Info

System:
    OS: Linux 5.15 Ubuntu 20.04.5 LTS (Focal Fossa)
    CPU: (4) x64 Intel(R) Core(TM) i5-2430M CPU @ 2.40GHz
    Memory: 1.26 GB / 5.71 GB
    Container: Yes
    Shell: 5.8 - /bin/zsh
  Binaries:
    Node: 16.14.2 - ~/.nvm/versions/node/v16.14.2/bin/node
    Yarn: 1.22.19 - /usr/bin/yarn
    npm: 8.5.0 - ~/.nvm/versions/node/v16.14.2/bin/npm
  Browsers:
    Chrome: 112.0.5615.165
    Firefox: 109.0
  npmPackages:
    @builder.io/qwik: 1.0.0 => 1.0.0 
    @builder.io/qwik-city: ^1.0.0 => 1.0.0 
    undici: 5.22.0 => 5.22.0 
    vite: 4.3.3 => 4.3.3

Additional Information

No response

estebanpanelli avatar May 15 '23 18:05 estebanpanelli

Hey @estebanpanelli, did you solve this issue?

gioboa avatar Sep 14 '23 16:09 gioboa

Hello @estebanpanelli. Please provide the missing information requested above. Issues marked with STATUS-2: missing info will be automatically closed if they have no activity within 14 days. Thanks 🙏

github-actions[bot] avatar Jun 14 '24 14:06 github-actions[bot]