QwikDev / qwik

Instant-loading web apps, without effort
https://qwik.dev
MIT License
20.84k stars 1.31k forks source link

[🐞] QWIK ERROR Error: must be non null #3440

Closed moxival closed 1 year ago

moxival commented 1 year ago

Which component is affected?

Qwik Runtime

Describe the bug

After upgrading to 0.22.0 Qwik throws QWIK ERROR Error: must be non null

This is what gets printed

QWIK ERROR Error: must be non null at createError (file:///[redacted]/node_modules/@builder.io/qwik/core.mjs:74:17) at logError (file:///[redacted]/node_modules/@builder.io/qwik/core.mjs:68:54) at must (file:///[redacted]/node_modules/@builder.io/qwik/core.mjs:7831:15) at serializeSubscription (file:///[redacted]/node_modules/@builder.io/qwik/core.mjs:7718:21) at file:///[redacted]/node_modules/@builder.io/qwik/core.mjs:3106:24 at Array.map (<anonymous>) at _pauseFromContexts (file:///[redacted]/node_modules/@builder.io/qwik/core.mjs:3102:14) at beforeClose (file:///[redacted]/node_modules/@builder.io/qwik/server.mjs:515:30) at file:///[redacted]/node_modules/@builder.io/qwik/core.mjs:3608:28 at file:///[redacted]/node_modules/@builder.io/qwik/core.mjs:4087:25 null

When I try to log at serializeSubscription with:

...
else if (type <= 2) {
        console.log('----------------------------------------', sub[0]);
        console.log(2, getObjId(sub[2]), sub[2]);

        base += ` ${must(getObjId(sub[2]))} ${must(getObjId(sub[3]))} ${sub[4]}`;
    }
...

I get

2 null SignalDerived {
  '$func$': [Function (anonymous)],
  '$args$': [
    SignalImpl {
      untrackedValue: 'https://..... 100w,\n' +
        'https://i......jpg 200w',
      [Symbol(proxy manager)]: 0,
      [Symbol(proxy manager)]: [LocalSubscriptionManager]
    }
  ],
  '$funcStr$': 'p0.value'
}

I am testing the still unreleased Image component of gioboa - it might be something wrong with the component but I still believe this error is very strange and does not give any information. I still do not understand what is wrong the component. If I remove the assignment srcSet={srcSetSignal.value} the error is no more.

Reproduction

none

Steps to reproduce

I have no idea how to reproduce this.

System Info

System:
    OS: Linux 5.19 Ubuntu 22.10 22.10 (Kinetic Kudu)
    CPU: (4) x64 Intel(R) Core(TM) i5-6400T CPU @ 2.20GHz
    Memory: 17.99 GB / 31.25 GB
    Container: Yes
    Shell: 5.2.2 - /usr/bin/bash
  Binaries:
    Node: 18.12.1 - ~/.nvm/versions/node/v18.12.1/bin/node
    Yarn: 1.22.19 - ~/.yarn/bin/yarn
    npm: 9.4.2 - ~/.nvm/versions/node/v18.12.1/bin/npm
  Browsers:
    Chrome: 111.0.5563.64
    Chromium: 111.0.5563.64
  npmPackages:
    @builder.io/qwik: ^0.23.0 => 0.23.0 
    @builder.io/qwik-city: ^0.6.5 => 0.6.5 
    @builder.io/qwik-react: ^0.5.0 => 0.5.0 
    undici: 5.21.0 => 5.21.0 
    vite: 4.2.0 => 4.2.0

Additional Information

No response

manucorporat commented 1 year ago

Can you provide a piece of code, or even better a stackblitz that reproduces the issue? Without a repo case, i can't prioritize this issue to get it fixed!

bhadreshp5 commented 1 year ago

@manucorporat I faced similar problem while learning qwik. Here's stackblitz https://stackblitz.com/edit/qwik-starter-xscsrx?file=src/routes/index.tsx

moxival commented 1 year ago

Hey Manu, sorry for my delayed response. I tried several times to reproduce this in stackblitz but i couldn't. Since the error is so obscure I am not sure that i understand exactly what is null and how to make it not null - or how to reproduce it.

Hopefully the stackblitz provided by @bhadreshp5 is the same issue as mine and that will help you debug it.

SebasG22 commented 1 year ago

I can confirm this issue is persistent. It's happening on some complex scenarios when I pass a useStore as parameter to a function when a click something. I tried to replicated on Stackblitz but it's not easy to reproduce with a simple app. I can share the logs that I'm getting over the serializeSubscription.

[vite] Internal server error: must be non null
      at createError (file:///Users/sebastian.velasquezg/Documents/code-craft-v2/node_modules/@builder.io/qwik/core.mjs:74:17)
      at logError (file:///Users/sebastian.velasquezg/Documents/code-craft-v2/node_modules/@builder.io/qwik/core.mjs:68:54)
      at must (file:///Users/sebastian.velasquezg/Documents/code-craft-v2/node_modules/@builder.io/qwik/core.mjs:7828:15)
      at serializeSubscription (file:///Users/sebastian.velasquezg/Documents/code-craft-v2/node_modules/@builder.io/qwik/core.mjs:7719:21)
      at file:///Users/sebastian.velasquezg/Documents/code-craft-v2/node_modules/@builder.io/qwik/core.mjs:3106:20
      at Array.map (<anonymous>)

The error on the screen does not give any clue about the real issue. To me is happening when you pass a state reference created with useStore y replaced with a regular object the error is gone.

image
Oddadmix commented 1 year ago

+1, It only happens when upgrading from 0.21.0 to 0.22

Looks like it has to do something with conditional chaining and a value is resolved to null or undefined.

gederer commented 1 year ago

I just got this error with my local Qwik/QwikCity build (latest stuff). I traced it to a signal in my JSX.

<img
            src={imagePathSignal.value}
            alt={`${product.name}`}
            class="h-full w-full object-cover object-center transition group-hover:opacity-75"
          />

Switched to this (trimmed the .value off imagePathSignal.value), and it works:

<img
            src={imagePathSignal}
            alt={`${product.name}`}
            class="h-full w-full object-cover object-center transition group-hover:opacity-75"
          />

Update:

This happens when I call {imagePathSignal.toString()} or {String(imagePathSignal)} in my JSX.

hth

Oddadmix commented 1 year ago

@manucorporat I faced similar problem while learning qwik. Here's stackblitz https://stackblitz.com/edit/qwik-starter-xscsrx?file=src/routes/index.tsx

@manucorporat, Please let us know if there is anything else needed.

jonathanlal commented 1 year ago

Just got the same issue, can't seem to get rid of it... All i did was rename some variables and add another item to initial state. Seems to be some kind of caching issue now

jonathanlal commented 1 year ago

removing any useSignals seems to fix it for me