react-three-fiber icon indicating copy to clipboard operation
react-three-fiber copied to clipboard

Suspense causes attach to be called multiple times

Open giulioz opened this issue 3 years ago • 5 comments
trafficstars

When using the attach prop with a function, its attach function gets called multiple times without a detach when a suspended sibiling component resumes. This causes potentially too many objects to be created.

Sandbox: https://codesandbox.io/s/append-bug-xslv50?file=/src/index.tsx

giulioz avatar May 03 '22 10:05 giulioz

I’m seeing a similar bug of objects being duplicated. I have not found what’s specific LT causing it. But I notice the error happens on iOS chrome and safari on first load but not on reload. Also desktop doesn’t have the problem. I’m not using suspense or attach, but it seems related.

clementshimizu avatar May 06 '22 09:05 clementshimizu

@clementshimizu if you can make a reproduction on codesandbox or similar we can get a better comparison. Looking into the above issue for the moment.

CodyJasonBennett avatar May 09 '22 09:05 CodyJasonBennett

Fix published in R3F 8.0.18. @clementshimizu, if you're still having issues, best to open an issue with a reproduction so we can take a closer look.

CodyJasonBennett avatar May 19 '22 18:05 CodyJasonBennett

Had to revert #2268 in 8.0.24 due to race conditions between useLayoutEffect/useEffect and the reconciler.

CodyJasonBennett avatar Jun 13 '22 23:06 CodyJasonBennett

Merged a fix into #2465, this can be expected to be released in the next v9 candidate.

CodyJasonBennett avatar Sep 03 '22 01:09 CodyJasonBennett