-
-
Notifications
You must be signed in to change notification settings - Fork 107
signals in react (three-fiber) doesn't work transiently #115
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
Comments
The reason this doesn't work is because we don't currently support fine-grained prop updates in the React integration. The Preact integration supports this because it injects fine-grained prop-to-DOM updates, but we cannot do that in React. However, it is possible to implement VDOM-based fine-grained updates in a way that works nicely with import { Signal } from '@preact/signals-react'
import * as rt from 'react/jsx-runtime'
import * as React from 'react'
rt.jsx = wrap(rt.jsx)
rt.jsxs = wrap(rt.jsxs)
let createElement = React.createElement
React.createElement = wrap(createElement)
const wrappers = new Map()
function wrap(method) {
return function (type) {
if (typeof type === 'string') {
let t = wrappers.get(type)
if (!t) wrappers.set(type, (t = Wrapper.bind(null, type)))
arguments[0] = t
}
return method.apply(this, arguments)
}
}
function Wrapper(type, props) {
let p = {}
for (let i in props) {
let v = props[i]
p[i] = i !== 'children' && v instanceof Signal ? v.value : v
}
return createElement(type, p)
} Here it is working with the original demo code unmodified: |
async function editSubscribers(subscriber) {
mainSets.value = {
...mainSets.value,
invitationChanges: {
friends: mainSets.value.invitationChanges.friends,
subscribers: mainSets.value.invitationChanges.subscribers.map((user) => {
if (user.pk === subscriber.pk) {
return { ...user, isInRoom: !user.isInRoom }
}
return user
})
}
}
} This function doesn't update mainSets.value.invitationChanges. subscribers |
Uh oh!
There was an error while loading. Please reload this page.
codesandbox: https://codesandbox.io/s/interesting-panna-urdtu6?file=/src/App.js
it's not a div, but it would be fantastic if it could work.
The text was updated successfully, but these errors were encountered: