[🐞] `useStore` reactivity is broken if key isn't initialized in store object
Which component is affected?
Qwik Runtime
Describe the bug
I am updating a store with an optional key. What I expect is downstream reactivity to occur based on the store's change. What actually is happening is no changes occur.
Reproduction
https://stackblitz.com/edit/qwik-starter-dgqpxj?file=src%2Froutes%2Findex.tsx
Steps to reproduce
Copied from reproduction link above:
const signalWithInit = useSignal('init');
const signalWithoutInit = useSignal<string | undefined>();
const storeWithInit = useStore<{ value: string }>({ value: 'init' });
const storeWithoutInit = useStore<{ value?: string }>({});
useVisibleTask$(
() => {
signalWithInit.value = 'visible-task';
signalWithoutInit.value = 'visible-task';
storeWithInit.value = 'visible-task';
storeWithoutInit.value = 'visible-task';
},
{ strategy: 'document-ready' }
);
storeWithoutInit.value will not trigger any downstream changes (e.g. rendering content or triggering tracks).
System Info
System:
OS: macOS 13.3.1
CPU: (10) arm64 Apple M1 Pro
Memory: 931.25 MB / 32.00 GB
Shell: 5.9 - /bin/zsh
Binaries:
Node: 18.13.0 - ~/.nvm/versions/node/v18.13.0/bin/node
npm: 8.19.3 - ~/.nvm/versions/node/v18.13.0/bin/npm
Browsers:
Chrome: 113.0.5672.92
Firefox Developer Edition: 113.0
Safari: 16.4
npmPackages:
@builder.io/qwik: ^1.1.1 => 1.1.1
@builder.io/qwik-city: ^1.1.1 => 1.1.1
undici: ^5.22.1 => 5.22.1
vite: 4.3.5 => 4.3.5
Additional Information
Here's the same repro code as above but in v1.0.0: https://stackblitz.com/edit/qwik-starter-odovoh?file=src%2Froutes%2Findex.tsx
It does render/function as expected there.
The workaround I'm going to attempt is to not have any optional keys in my store types and instead have it defaulted to undefined instead.
Start a new pull request in StackBlitz Codeflow.
Highest priority to fix! also, add a new regression test. Working on it!
We got a fix!
Short question, since it's about broken reactivity and it was introduced with v1.1.0, could it fix the context reactivity problem too? https://discord.com/channels/842438759945601056/1106601727458824302/1106601727458824302
@Zeiver the discord thread does not have much source code i can use to reproduce. As a rule thumb, if you want a bug to be fixed, github is the place!! I pay x50 times more attention to github issues than conversations in Discord.
The reason is because i need the issue reporter to fill the issue template correctly, it really saves time
Okay gonna try to create an example with Stackblitz.
https://stackblitz.com/edit/node-xenwez?file=src/components/starter/example/example.tsx So I only created a 1.1.0 version, but it's the same problem. If I give the store an initial value even if it's undefined for { text?: string } then it works. @manucorporat
And I gave up on stackblitz, tried to create anything in that and nothing is working. Create a new repo, pushed my stuff there and loaded it with stackblitz.