You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
"react": "19.0.0-rc-107a2f8c3e-20240617",
"react-dom": "19.0.0-rc-107a2f8c3e-20240617"
OS : windows 11
Chrome : 125.0.6422.142
Overview
We have a great feature 'functional form action' in react 19. <form action={functionalFormAction}
but with React lazy, it doesn't seem to work properly.
It causes infinite loop depends on its use cases.
case1 : infinite loop (React lazy without <Suspense/>. All dynamic codes are inside form component)
case2 : no infinite loop (React lazy with <Suspense/>. All dynamic codes are inside form component)
case3 : infinite loop (React lazy with <Suspsne /> & has dependency on useFormStatus. All dynamic code are inside form component)
Related Issues
#29235 Bug: Nested lazy components cause rerendering #27573 Bug: Nested components imported with React.lazy cause rerendering
Reproduction
Go to CodeSandBox
Try Case2 at first, (submit form by clicking button)
Try Case3 at second, (it causes infinite loop so it makes js blocked)
Try Case1 at the last (it causes infinite loop so it makes js blocked)
Preview
App.tsx
Case1.tsx
Case 1 Result
Case 2 Result
Case 3 Result
The text was updated successfully, but these errors were encountered:
You are creating a new, lazy component within render. The component type is therefore changing on every render. Then React has to re-render when the lazy resolves but encounters a new lazy component since you called lazy() again. This is expected behavior.
Do you still enter an infinite loop if you move the component creation outside of render?
Do you still enter an infinite loop if you move the component creation outside of render?
I was able to prevent infinite loop for 'Case 1'. But unfortunately, 'Case 3' is still suffering from infinite loop.
And, moving the React.lazy outside of render has limits. Due to the inability to utilize component props, 'React.lazy' can only be used statically.
for example, I have an component that takes file names as props and renders dynamically based on them. According to the proposed solution, this code can no longer be used.
And, moving the React.lazy outside of render has limits. Due to the inability to utilize component props, 'React.lazy' can only be used statically.
You need to implement a client cache then. React doesn't have that capabiltiy at the moment. Unconditionally creating React.lazy during render is not supported. Just like you couldn't create a new Promise during render and pass it to use.
It's probably better to use some form of codegen to create the icons anyway so that all available icons are known statically.
I was able to prevent infinite loop for 'Case 1'. But unfortunately, 'Case 3' is still suffering from infinite loop.
Do you have a repro just for that case with the React.lazy created outside of render?
Summary
Version
"react": "19.0.0-rc-107a2f8c3e-20240617",
"react-dom": "19.0.0-rc-107a2f8c3e-20240617"
OS : windows 11
Chrome : 125.0.6422.142
Overview
We have a great feature 'functional form action' in react 19.
<form action={functionalFormAction}
but with React lazy, it doesn't seem to work properly.
It causes infinite loop depends on its use cases.
<Suspense/>
. All dynamic codes are inside form component)<Suspense/>
. All dynamic codes are inside form component)<Suspsne />
& has dependency on useFormStatus. All dynamic code are inside form component)Related Issues
#29235 Bug: Nested lazy components cause rerendering
#27573 Bug: Nested components imported with React.lazy cause rerendering
Reproduction
Go to CodeSandBox
Try Case2 at first, (submit form by clicking button)
Try Case3 at second, (it causes infinite loop so it makes js blocked)
Try Case1 at the last (it causes infinite loop so it makes js blocked)
Preview
App.tsx
![image](https://private-user-images.githubusercontent.com/17701725/341027659-1300ae79-1c3c-4f79-bd82-06e723ed6b9f.png?jwt=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJnaXRodWIuY29tIiwiYXVkIjoicmF3LmdpdGh1YnVzZXJjb250ZW50LmNvbSIsImtleSI6ImtleTUiLCJleHAiOjE3MjAyNDEzNDQsIm5iZiI6MTcyMDI0MTA0NCwicGF0aCI6Ii8xNzcwMTcyNS8zNDEwMjc2NTktMTMwMGFlNzktMWMzYy00Zjc5LWJkODItMDZlNzIzZWQ2YjlmLnBuZz9YLUFtei1BbGdvcml0aG09QVdTNC1ITUFDLVNIQTI1NiZYLUFtei1DcmVkZW50aWFsPUFLSUFWQ09EWUxTQTUzUFFLNFpBJTJGMjAyNDA3MDYlMkZ1cy1lYXN0LTElMkZzMyUyRmF3czRfcmVxdWVzdCZYLUFtei1EYXRlPTIwMjQwNzA2VDA0NDQwNFomWC1BbXotRXhwaXJlcz0zMDAmWC1BbXotU2lnbmF0dXJlPTcyNTQ4Y2FlYzQyZWRiZGE3MWU2NGFkMmY2OTlhNGJmYTk2YjI0ZWIzZGEwMDIxYjE1NjQ1YzMzNjQ2Yjc5MjAmWC1BbXotU2lnbmVkSGVhZGVycz1ob3N0JmFjdG9yX2lkPTAma2V5X2lkPTAmcmVwb19pZD0wIn0.UpB8dMoKLU5JzZQuUKmGvDNvmh8aD3E2LOk6-aqUp-s)
Case1.tsx
![image](https://private-user-images.githubusercontent.com/17701725/341027774-761d08d4-8fd7-4692-b0a8-954f1124df48.png?jwt=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJnaXRodWIuY29tIiwiYXVkIjoicmF3LmdpdGh1YnVzZXJjb250ZW50LmNvbSIsImtleSI6ImtleTUiLCJleHAiOjE3MjAyNDEzNDQsIm5iZiI6MTcyMDI0MTA0NCwicGF0aCI6Ii8xNzcwMTcyNS8zNDEwMjc3NzQtNzYxZDA4ZDQtOGZkNy00NjkyLWIwYTgtOTU0ZjExMjRkZjQ4LnBuZz9YLUFtei1BbGdvcml0aG09QVdTNC1ITUFDLVNIQTI1NiZYLUFtei1DcmVkZW50aWFsPUFLSUFWQ09EWUxTQTUzUFFLNFpBJTJGMjAyNDA3MDYlMkZ1cy1lYXN0LTElMkZzMyUyRmF3czRfcmVxdWVzdCZYLUFtei1EYXRlPTIwMjQwNzA2VDA0NDQwNFomWC1BbXotRXhwaXJlcz0zMDAmWC1BbXotU2lnbmF0dXJlPWY5ZGRiOTFlNGY4MGIwNTY5ODBjMmQyMDg4YzA2OWQwOTVhOWU1N2JhYjlhNzI0OTRmNDRlZGY2OTMyOTg0MGEmWC1BbXotU2lnbmVkSGVhZGVycz1ob3N0JmFjdG9yX2lkPTAma2V5X2lkPTAmcmVwb19pZD0wIn0.cP5c_1KzGZb_PB1EzV6_-m7MCBaralYx9XFAL6W7CMw)
Case 1 Result
![image](https://private-user-images.githubusercontent.com/17701725/341027130-f18f610c-7b4b-42fe-88b9-4bd8addc5d86.png?jwt=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJnaXRodWIuY29tIiwiYXV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FFLNFpBJTJGMjAyNDA3MDYlMkZ1cy1lYXN0LTElMkZzMyUyRmF3czRfcmVxdWVzdCZYLUFtei1EYXRlPTIwMjQwNzA2VDA0NDQwNFomWC1BbXotRXhwaXJlcz0zMDAmWC1BbXotU2lnbmF0dXJlPWExNTRkOTg5ZTYzNGZlMzBkZjJmZTkxNDFkMjc5OWM1MDdmYmY1Mzc5MmZiODA1MzI2MWRkNTBlMDJmZTVkOGImWC1BbXotU2lnbmVkSGVhZGVycz1ob3N0JmFjdG9yX2lkPTAma2V5X2lkPTAmcmVwb19pZD0wIn0.JgdEyeYyEMYz9hcuUo91UQjjWTebVtjaqG2rQs85cuQ)
Case 3 Result
![image](https://private-user-images.githubusercontent.com/17701725/341026867-4eac93e2-e498-483c-9a8c-7bc99c2b20b9.png?jwt=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJnaXRodWIuY29tIiwiYXVkIjoicmF3LmdpdGh1YnVzZXJjb250ZW50LmNvbSIsImtleSI6ImtleTUiLCJleHAiOjE3MjAyNDEzNDQsIm5iZiI6MTcyMDI0MTA0NCwicGF0aCI6Ii8xNzcwMTcyNS8zNDEwMjY4NjctNGVhYzkzZTItZTQ5OC00ODNjLTlhOGMtN2JjOTljMmIyMGI5LnBuZz9YLUFtei1BbGdvcml0aG09QVdTNC1ITUFDLVNIQTI1NiZYLUFtei1DcmVkZW50aWFsPUFLSUFWQ09EWUxTQTUzUFFLNFpBJTJGMjAyNDA3MDYlMkZ1cy1lYXN0LTElMkZzMyUyRmF3czRfcmVxdWVzdCZYLUFtei1EYXRlPTIwMjQwNzA2VDA0NDQwNFomWC1BbXotRXhwaXJlcz0zMDAmWC1BbXotU2lnbmF0dXJlPTAwNTYxOTlmMjVmMjI2NGE0MzE3YmIyZThmZjM1ODcxYjdmZmU3ZmE0MTdiODgzYjc1OGRmYzk1YzE5ZGI2MWImWC1BbXotU2lnbmVkSGVhZGVycz1ob3N0JmFjdG9yX2lkPTAma2V5X2lkPTAmcmVwb19pZD0wIn0.cFfD8bM3EY11SNySO6vrS6HQK69NIw763IbtvGre9Fs)
The text was updated successfully, but these errors were encountered: