-
-
Notifications
You must be signed in to change notification settings - Fork 1.6k
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
[v9] fix(events): bubble up primitives #3032
base: v9
Are you sure you want to change the base?
Conversation
This pull request is automatically built and testable in CodeSandbox. To see build info of the built libraries, click here or the icon next to each commit SHA. Latest deployment of this branch, based on commit 9a99a14:
|
This reverts commit 4d59d9c.
Does this work on v8? What's the cause of this discrepancy if we haven't changed events, but only internal reconciler code? |
Good question. I just checked. To real difference is here though. In v8, if there is no R3F prop on the object it just uses the default root store. This looks better than traversing. But I still wonder if it's still better to process all children of a function handleIntersects(
intersections: Intersection[],
event: DomEvent,
delta: number,
callback: (event: ThreeEvent<DomEvent>) => void,
) {
const rootState = store.getState() // <--
if (intersections.length) {
const localState = { stopped: false }
for (const hit of intersections) {
const state = getRootState(hit.object) || rootState // <-- |
We can only assume that imperative children are fully dynamic, so we can't rely on any of their properties to persist with time. I believe this issue was lost in a much earlier refactor when we braced against suspense -- react-three-fiber/packages/fiber/src/core/reconciler.tsx Lines 115 to 138 in c5694ee
This doesn't affect cases where events propagate up from imperative children to the primitive element though. |
That's a good catch. And yeah that makes sense about the children being dynamic. I think traversing up is the best solution so that portaling is respected. |
Events were completely broken for
primitive
elements. The main reason is that with aprimitive
you can add a tree fragment to the scene but only the top most element gets processed for an___r3f
property. Since all children are missing this, when they get hit by a raycaster they then fail thegetRootState
call. Similarly,primitive
elements were failing to get added toineternal.interactions
object as aprimitive
would get processed withapplyProps
before it had a parent. I don't know why this is. This PR does the following:ineternal.interactions
function. I'm not sure what this check was doing in the first place. If we need it, we'll have to figure out whyapplyProps
is run before it has a parent.getRootState
.An alternative would be to process all children of a
primitive
fragment to give them R3F metadata.