fix(vue3): update reactive globals before calling storyFn#34528
fix(vue3): update reactive globals before calling storyFn#34528SAY-5 wants to merge 1 commit intostorybookjs:nextfrom
Conversation
When the story re-renders without a full remount, globals were being updated after storyFn ran, so decorators saw stale plain objects instead of the reactive proxies. Moved the updateArgs calls for both globals and args to happen before storyFn, and replaced the context references with the reactive versions so the whole chain stays in sync. Fixes storybookjs#34319
📝 WalkthroughWalkthroughThe Changes
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~20 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.
Caution
Some comments are outside the diff and can’t be posted inline due to platform limitations.
⚠️ Outside diff range comments (1)
code/renderers/vue3/src/render.ts (1)
165-167:⚠️ Potential issue | 🟠 MajorRemove the empty-object early return in
updateArgs(bug persists on key removal).At Line 165, returning early when
nextArgsis{}skips the deletion loop, so removed globals/args remain in the reactive object. That keeps stale keys alive and can still desync state.Proposed fix
export function updateArgs< T extends { [name: string]: unknown; }, >(reactiveArgs: T, nextArgs: T) { - if (Object.keys(nextArgs).length === 0) { - return; - } const currentArgs = isReactive(reactiveArgs) ? reactiveArgs : reactive(reactiveArgs); // delete all args in currentArgs that are not in nextArgs Object.keys(currentArgs).forEach((key) => { if (!(key in nextArgs)) { delete currentArgs[key]; } }); // update currentArgs with nextArgs Object.assign(currentArgs, nextArgs); }🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@code/renderers/vue3/src/render.ts` around lines 165 - 167, In updateArgs, remove the early return that bails when Object.keys(nextArgs).length === 0 so the subsequent deletion pass runs and removed keys are actually deleted from the reactive args; ensure the function still compares prevArgs and nextArgs as before and runs the existing deletion loop (the loop that iterates over prevArgs/its keys and deletes any key not present in nextArgs) so stale keys are removed when nextArgs is empty or when keys are removed.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Outside diff comments:
In `@code/renderers/vue3/src/render.ts`:
- Around line 165-167: In updateArgs, remove the early return that bails when
Object.keys(nextArgs).length === 0 so the subsequent deletion pass runs and
removed keys are actually deleted from the reactive args; ensure the function
still compares prevArgs and nextArgs as before and runs the existing deletion
loop (the loop that iterates over prevArgs/its keys and deletes any key not
present in nextArgs) so stale keys are removed when nextArgs is empty or when
keys are removed.
ℹ️ Review info
⚙️ Run configuration
Configuration used: Organization UI
Review profile: CHILL
Plan: Pro
Run ID: 108f4b98-792a-466e-958c-92e92e16e76a
📒 Files selected for processing (1)
code/renderers/vue3/src/render.ts
When a story re-renders without a full remount, globals were being updated after storyFn ran. Decorators would see stale plain objects instead of the reactive proxies, causing the globals state to desync from Vue's reactivity system.
Moved the updateArgs calls for globals and args to happen before storyFn is called, and swapped the context references to use the reactive versions. This way the entire decorator chain sees the same reactive objects that Vue is tracking.
Fixes #34319
Summary by CodeRabbit