fix(vue3): clear stale args/globals when nextArgs is empty in updateArgs#34327
fix(vue3): clear stale args/globals when nextArgs is empty in updateArgs#34327mixelburg wants to merge 1 commit intostorybookjs:nextfrom
Conversation
When updateArgs() was called with an empty nextArgs object (e.g. when
resetting args or clearing toolbar globals), the early return left all
existing keys in reactiveArgs/reactiveGlobals intact. Stale values
would then persist in Vue decorators even after a reset.
Remove the early return so the deletion loop always runs, leaving the
reactive object empty when nextArgs is {}.
Fixes storybookjs#34319
📝 WalkthroughWalkthroughThe Changes
Estimated code review effort🎯 2 (Simple) | ⏱️ ~8 minutes Possibly related PRs
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
🧹 Nitpick comments (1)
code/renderers/vue3/src/render.test.ts (1)
94-98: Good regression test for the emptynextArgsfix.The test correctly covers the scenario from issue
#34319. One minor suggestion: consider using the generic type parameter pattern already established elsewhere in this file (lines 28, 42, 58) instead of theas anycast for better type safety.♻️ Suggested type-safe alternative
it('clears all args when nextArgs is empty -> updateArgs()', () => { const reactiveArgs = reactive({ argFoo: 'foo', argBar: 'bar' }); - updateArgs(reactiveArgs, {} as any); + updateArgs<Args>(reactiveArgs, {}); expect(reactiveArgs).toEqual({}); });🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@code/renderers/vue3/src/render.test.ts` around lines 94 - 98, The test uses an unsafe cast (`as any`) when calling updateArgs; replace that cast with the generic type parameter pattern used elsewhere in this file by invoking updateArgs with the inferred/explicit generic for the reactiveArgs variable (e.g., use the same generic style as the other tests instead of `as any`) so the call to updateArgs(reactiveArgs, ...) is type-safe; update the invocation that references updateArgs and reactiveArgs to use the generic type parameter form.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Nitpick comments:
In `@code/renderers/vue3/src/render.test.ts`:
- Around line 94-98: The test uses an unsafe cast (`as any`) when calling
updateArgs; replace that cast with the generic type parameter pattern used
elsewhere in this file by invoking updateArgs with the inferred/explicit generic
for the reactiveArgs variable (e.g., use the same generic style as the other
tests instead of `as any`) so the call to updateArgs(reactiveArgs, ...) is
type-safe; update the invocation that references updateArgs and reactiveArgs to
use the generic type parameter form.
ℹ️ Review info
⚙️ Run configuration
Configuration used: Organization UI
Review profile: CHILL
Plan: Pro
Run ID: d6869e50-8679-4dc5-a7ba-be406ffce20c
📒 Files selected for processing (2)
code/renderers/vue3/src/render.test.tscode/renderers/vue3/src/render.ts
💤 Files with no reviewable changes (1)
- code/renderers/vue3/src/render.ts
What does this PR do?
Fixes the bug where stale args/globals persisted in Vue decorators after resetting args or clearing toolbar globals.
When
updateArgs()was called with an emptynextArgsobject, the early return on line 156 skipped the deletion loop entirely. This left every existing key inreactiveArgs/reactiveGlobalsalive, so resetting args or clearing toolbar globals back to{}had no effect on the Vue reactive objects.Fix
Remove the early return so the deletion loop always runs. When
nextArgsis{}, all keys incurrentArgsare deleted, resulting in a properly empty reactive object.Test
Added a regression test:
updateArgs(reactive({ argFoo: 'foo', argBar: 'bar' }), {})now results in an empty object.Fixes #34319
Summary by CodeRabbit
Bug Fixes
Tests