fix: pass mapped textures to onLoad callback in useTexture#2696
fix: pass mapped textures to onLoad callback in useTexture#2696MichaelangJason wants to merge 1 commit intopmndrs:masterfrom
Conversation
|
@MichaelangJason is attempting to deploy a commit to the Poimandres Team on Vercel. A member of the Team first needs to authorize it. |
|
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. |
travisbreaks
left a comment
There was a problem hiding this comment.
The fix is correct — onLoad was receiving raw loader output instead of the mapped texture record. Moving useMemo above useLayoutEffect ensures mappedTextures is computed before the callback fires.
One note: the useLayoutEffect dependency array is [onLoad] but doesn't include mappedTextures. If the textures change (e.g., dynamic URL swap), onLoad won't re-fire with the new mapped textures unless the callback reference also changes. This matches the existing behavior before this PR, so not a regression — but worth noting for anyone expecting onLoad to fire on texture updates.
The fix itself is clean and minimal. LGTM on the core change.
@travisbreaks Thank you so much for the code review! Sorry for the late reply. |
|
Hi @DennisSmolek ! Just following up on this PR whenever you have a chance to take a look. I’d really appreciate any feedback on whether these changes address the issue correctly, and specifically whether I noticed the project seems to be focused on v11, so I understand if this PR is lower priority at the moment. I took a quick look at the v11 code, and it seems these changes could likely be applied there as well without modification. If that would be more useful, I’d be happy to open a separate PR for v11 or retarget this one to it. Since this is my first contribution to an open-source project, I’d also appreciate any guidance on the best next step. Thanks for your time! |
9ff40e1 to
fd093de
Compare
Why
onLoadcallback foruseTextureis typed to acceptMappedTextureType<Url>, which includesTextureRecord<Url>. However,onLoadis called with the raw output ofuseLoader, which is cast toMappedTextureType<Url>but will never actually be aTextureRecord<Url>(only_Texture[]or_Texture, respectively,TextureArray<Url>andSingleTexture<Url>). This means anonLoadcallback expecting aTextureRecord<Url>would receive an array instead of a keyed object.What
This PR moves the
useMemocall before theuseLayoutEffect, and passes the correctly structuredmappedTexturesto theonLoadcall.I noticed that the original
useLayoutEffectdidn't include textures in its dependency list. I assumed this was intentional to avoid re-firingonLoadunnecessarily, so I kept the same pattern and didn't includemappedTexturesin the dependency list either.Checklist