-
-
Notifications
You must be signed in to change notification settings - Fork 926
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Mutables need batching in some situations #960
Comments
Ultimately the issue here is the array ends up with a hole at the end which throws an error when you access
I think the fix here might actually be simple. The |
Making this change does mean you wouldn't be able to set an item in an array to undefined as it would splice it out instead. To be fair, the current implementation isn't ideal here either as the deleted item isn't iterated with things like |
Yeah I don't know I like that. I'm gathering the reason batch works is in the end the proxy sets the length but not as it goes. The real problem is the batching I gather. If there is a clever fix for that it may be the best option. |
Yeah, this is pretty interesting. I would have assumed array operations would be atomic but with proxies we can interrupt them and see how they are implemented. For instance My previous though only sort of solved it in a round about way but you're right it doesn't remove the intermediate notifications which are wasteful at best and otherwise glitchy. New idea: In the if (typeof value === 'function' && Array.prototype[property] === value) {
return (...args) => batch(() => value.apply(receiver, args))
} |
Posted something similar in discord, I got the prototype wrapped in batch, but still only works sometimes, if you press pop twice the second time gives an error from mapArray |
@titoBouzout I think your example is just missing returning the result of the wrapped function from within the batch which appears to prevent something from getting a value back from a |
Ah yeah, thank you. Updated example https://playground.solidjs.com/?hash=805667632&version=1.3.16 |
This seems like a good idea to me. Alternatively, we could have a white-list of certain operations (e.g. |
Mutable issues in 1.4
const mutable = createMutable({ roomID: 'lobby' })
console.log(mutable.roomID) // prints 'lobby'
mutable.roomID = 'soemthing else'
console.log(mutable.roomID) // GOOD: prints 'soemthing else' If you do onMount, it won't work onMount(() => {
const mutable = createMutable({ roomID: 'lobby' })
console.log(mutable.roomID) // prints 'lobby'
mutable.roomID = 'soemthing else'
console.log(mutable.roomID) // BAD: will print lobby
})
function patchMutable(mutable, key, data) {
if (mutable[key].id !== data.id) {
mutable[key] = data
} else {
modifyMutable(mutable[key], reconcile(data))
}
}
const mutable = createMutable({
room: { id: 'lobby', users: [1, 2] },
})
// correctly will set mutable-length-original="2"
document.body.setAttribute(
'mutable-length-original',
mutable.room.users.length,
)
patchMutable(mutable, 'room', { id: 'lobby', users: [] })
// correctly will set mutable-length-patched="0"
document.body.setAttribute(
'mutable-length-patched',
mutable.room.users.length,
)
// here is the problem
socket.on('room', data => {
patchMutable(state, 'room', data)
state.roomID = state.room.id
document.body.setAttribute('room', state.room.id)
// will set user-count="(...args) => batch(() => Array.prototype[property].apply(receiver, args))"
document.body.setAttribute('user-count', state.room.users.length)
})
|
Describe the bug
Mutables behave in unexpected ways in some situations
In the cats example, pop() doesn't trigger an update
https://playground.solidjs.com/?hash=-1685740014&version=1.3.16
However, if you batch it, it works
https://playground.solidjs.com/?hash=1329499387&version=1.3.16
When doing push() it doesn't need batching and works as expected
https://playground.solidjs.com/?hash=-445597428&version=1.3.16
Lack of batching when in use with reconcile triggers unnecessary re-renders
https://playground.solidjs.com/?hash=-1814354602&version=1.3.7
Not sure if this will be related to this, but working with arrays doesn't trigger an update
https://playground.solidjs.com/?hash=-1939954988&version=1.3.16
Your Example Website or App
https://playground.solidjs.com/
Steps to Reproduce the Bug or Issue
Expected behavior
Screenshots or Videos
Platform
Additional context
The text was updated successfully, but these errors were encountered: