Repository navigation
feat: gracefully skip nullish values in storeToRefs - #3134
Conversation
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: defaults Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (1)
✅ Files skipped from review due to trivial changes (1)
📝 WalkthroughWalkthrough
ChangesstoreToRefs null guard fix
Estimated code review effort🎯 1 (Trivial) | ⏱️ ~3 minutes Suggested reviewers
Poem
🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches🧪 Generate unit tests (beta)
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)
packages/pinia/__tests__/storeToRefs.spec.ts (1)
215-217: ⚡ Quick winStrengthen the regression by asserting the null non-ref key is excluded
This test proves the crash is fixed, but it should also lock in expected behavior that
nullableItemis skipped in setup-store refs.Suggested test tightening
- expect(() => storeToRefs(store)).not.toThrow() - const { text } = storeToRefs(store) - expect(text.value).toBe('hello') + expect(() => storeToRefs(store)).not.toThrow() + const refs = storeToRefs(store) + expect(refs).not.toHaveProperty('nullableItem') + expect(refs.text.value).toBe('hello')🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@packages/pinia/__tests__/storeToRefs.spec.ts` around lines 215 - 217, The test currently verifies that storeToRefs does not throw and checks the text property, but it does not assert that the nullableItem key (which is null) is excluded from the refs returned. Add an additional assertion after obtaining the refs from storeToRefs to verify that nullableItem is undefined or not present in the destructured refs, ensuring that null non-ref keys are properly skipped in setup-store refs and strengthening the regression test.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Nitpick comments:
In `@packages/pinia/__tests__/storeToRefs.spec.ts`:
- Around line 215-217: The test currently verifies that storeToRefs does not
throw and checks the text property, but it does not assert that the nullableItem
key (which is null) is excluded from the refs returned. Add an additional
assertion after obtaining the refs from storeToRefs to verify that nullableItem
is undefined or not present in the destructured refs, ensuring that null non-ref
keys are properly skipped in setup-store refs and strengthening the regression
test.
ℹ️ Review info
⚙️ Run configuration
Configuration used: defaults
Review profile: CHILL
Plan: Pro
Run ID: c9d1248f-83ac-4c28-8c55-9968ff4d11a2
📒 Files selected for processing (2)
packages/pinia/__tests__/storeToRefs.spec.tspackages/pinia/src/storeToRefs.ts
posva
left a comment
There was a problem hiding this comment.
Thanks! This is actually not valid but the runtime change is worth having.
Bug
storeToRefsthrowsTypeError: Cannot read properties of null (reading 'effect')when a setup store returns a non-refnullvalue as part of its state (closes #3123).The loop in
storeToRefsiterates all enumerable keys in the raw store. When a setup store returns a rawnullvalue (not wrapped inref()),rawStore[key]is literallynull, and the unguardedvalue.effectaccess throws.Fix
Add a null-guard before the
.effectaccess:The guard is consistent with how
isRefandisReactivealready handle nullish values. A null (or undefined) raw value is simply skipped — the same outcome as any other non-ref, non-reactive value.Verification
Red (before): test failed with
TypeError: Cannot read properties of null (reading 'effect')Green (after): all 10 storeToRefs tests pass, including the new regression test.
Summary by CodeRabbit
Bug Fixes
storeToRefscould throw when a setup store includes optional state values that arenull(non-ref).Tests
storeToRefsdoes not throw withnulloptional state and that existing refs are still returned and readable.