ITADN

[🐞] v1&v2: tracking optional property default-initialized by function call does not re-run task

#8576OpenFloezeTv 创建于 2026-04-25
bugruntimereactivity
F
FloezeTvcommented
### Which component is affected? Qwik Runtime ### Describe the bug When a component's optional prop is assigned the result of a function call as a default value and the property changes, a task tracking that property is not rerun, even though the property changed. Initializing the prop to a constant works as expected and reruns the task. #### Example The example-code below creates two components where the only difference is how the optional prop `value` is initialized to a constant in `ComponentA` and to the result of a function-call in `ComponentB`: ```tsx const getValue = (): number => 0; const ComponentA = component$(({ value = 0 }: { value?: number }) => { useTask$(({ track }) => console.log( "Component A task value:", track(() => value), ), ); console.log("Component A value:", value); return <div>Component A value: {value}</div>; }); const ComponentB = component$(({ value = getValue() }: { value?: number }) => { useTask$(({ track }) => console.log( "Component B task value:", track(() => value), ), ); console.log("Component B value:", value); return <div>Component B value: {value}</div>; }); export default component$(() => { const num = useSignal(0); return ( <> <button onClick$={() => num.value++}>Click me</button> <ComponentA value={num.value} /> <ComponentB value={num.value} /> </> ); }); ``` With these components, clicking the button produces the following console-log: ``` Component A task value: 1 Component B value: 1 Component A value: 1 Component A task value: 2 Component A value: 2 Component B value: 2 Component A task value: 3 Component A value: 3 Component B value: 3 ``` `ComponentA`'s task is correctly re-run when the value changes, while `ComponentB`'s task is never re-run. The value of the property is changing as indicated by the `Component B value: <>`-logs and the text updating in the browser. Both tasks are executed once on the server: ``` Component A task value: 0 Component A value: 0 Component B task value: 0 Component B value: 0 ``` ### Reproduction v1: https://github.com/FloezeTv/qwik-default-props-task-rerun/tree/v1 v2: https://github.com/FloezeTv/qwik-default-props-task-rerun/tree/v2 ### Steps to reproduce - Create a new project (v1 or v2) (`npm create qwik` / `npm create qwik@2.0.0-beta.32`) - Create a component like `ComponentB` from the example, where an optional prop is assigned a default value from a function call and then tracked in a task - Update the component's prop and check if the task is executed ### System Info ```shell System: OS: Linux 6.12 Manjaro Linux CPU: (16) x64 AMD Ryzen 7 5700U with Radeon Graphics Memory: 9.19 GB / 38.58 GB Container: Yes Shell: 5.9 - /bin/zsh Binaries: Node: 25.8.1 - /usr/bin/node npm: 11.11.1 - /usr/bin/npm pnpm: 10.32.1 - /usr/bin/pnpm bun: 1.3.11 - /usr/bin/bun Deno: 2.7.5 - /usr/bin/deno Browsers: Firefox: 150.0 Firefox Developer Edition: 150.0 npmPackages: @qwik.dev/core: ^2.0.0-beta.32 => 2.0.0-beta.32 @qwik.dev/router: ^2.0.0-beta.32 => 2.0.0-beta.32 typescript: 5.9.3 => 5.9.3 vite: 7.3.1 => 7.3.1 ``` ### Additional Information _No response_
0 条评论