Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/vanilla.ts
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ const createSnapshotDefault = <T extends object>(
}
Object.defineProperty(snap, key, desc)
})
return Object.preventExtensions(snap)
return snap
Comment thread
dai-shi marked this conversation as resolved.
}

const createHandlerDefault = <T extends object>(
Expand Down
20 changes: 0 additions & 20 deletions tests/snapshot.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,26 +24,6 @@ describe('snapshot', () => {
expect(snap1).toBe(snap2)
})

it('should make the snapshot immutable', () => {
const state = proxy<{ foo: number; bar?: string }>({ foo: 1 })
const snap = snapshot(state)

// Overwriting existing property
expect(() => {
;(snap as typeof state).foo = 100
}).toThrow()

// Extension (adding new property)
expect(() => {
;(snap as typeof state).bar = 'hello'
}).toThrow()

// Note: The current implementation does not prevent property removal.
// Do not add a test for this unless we come up with an implementation that
// supports it.
// See https://github.com/pmndrs/valtio/issues/749
})

it('should not cause proxy-compare to copy', async () => {
const state = proxy({ foo: 1 })
const snap1 = snapshot(state)
Expand Down