use-cannon icon indicating copy to clipboard operation
use-cannon copied to clipboard

Remove internal suspense boundary

Open alexandernanberg opened this issue 3 years ago • 4 comments

I can't see a good reason why there is a suspense boundary inside the library, this should ideally be handled by consumers for more granular control. E.g. consumer might not want to render null.

https://github.com/pmndrs/use-cannon/blob/543f3e243947ff68488f549208417289cde60fdd/src/index.tsx#L8-L14

This would unfortunately be a breaking change, but in the long run I think it's a good one.

alexandernanberg avatar Oct 31 '21 08:10 alexandernanberg

Would it be useful to provide a fallback property to the props?

bjornstar avatar Nov 04 '21 08:11 bjornstar

Not really for my use-case tbh, because it doesn't enable composability in the same way.

E.g. imagine this scenario

<Canvas>
	<Suspense fallback={<Loading />}>
		<ComponentThatLoadsAsset />
		<Physics>
			<ComponentThatLoadsAsset />
		</Physics>
	</Suspense>
</Canvas>

alexandernanberg avatar Nov 04 '21 12:11 alexandernanberg

i agree, it would be more flexible if it's in userland. it is a breaking change though, would require a new major.

btw @alexandernanberg your example wouldn't work, you can't have raw text or dom nodes within the canvas, but this would be ok:

<Suspense fallback="Loading...">
  <Canvas>	
    <ComponentThatLoadsAsset />
    <Physics>
      <ComponentThatLoadsAsset />
    </Physics>
  </Canvas>
</Suspense>

drcmda avatar Nov 04 '21 12:11 drcmda

@drcmda Oh right, good point, was just quickly typing out pseudo-code 😄

alexandernanberg avatar Nov 04 '21 12:11 alexandernanberg