fix(slot): Handle RSC lazy references with non-PromiseLike payloads #3777
+21 −10
Add this suggestion to a batch that can be applied as a single commit. This suggestion is invalid because no changes were made to the code. Suggestions cannot be applied while the pull request is closed. Suggestions cannot be applied while viewing a subset of changes. Only one suggestion per line can be applied in a batch. Add this suggestion to a batch that can be applied as a single commit. Applying suggestions on deleted lines is not supported. You must change the existing code in this line in order to create a valid suggestion. Outdated suggestions cannot be applied. This suggestion has been applied or marked resolved. Suggestions cannot be applied from pending reviews. Suggestions cannot be applied on multi-line comments. Suggestions cannot be applied while the pull request is queued to merge. Suggestion cannot be applied right now. Please check back later.
Summary
Use
Children.toArrayinSlotCloneto properly unwrap React lazy components that have non-PromiseLike payloads (common in RSC context).Problem: The existing
isLazyComponentcheck requiresisPromiseLike(element._payload), but in RSC context the_payloadmay have a different structure, causing lazy references to slip through and breakcloneElement. This results in components not rendering in production builds.Solution: Use
Children.toArraywhich internally resolves lazy children regardless of payload structure, making it a robust solution for RSC compatibility.Fixes #3776
Changes
isLazyComponent+isValidElement(children)approach withChildren.toArrayincreateSlotCloneTest plan
Related issues
cloneElementin client component with async server component as children not working facebook/react#32392