next.js
3c84b3ac - Add useOptimistic to client-only errors (#53313)

Commit
2 years ago
Add useOptimistic to client-only errors (#53313) ### What? This PR makes it so calling `experimental_useOptimistic` throws an error telling you it only works in a client component. Because the Next docs have an example of renaming it into `useOptimistic` in the import, I also added that as a forbidden import. There may be a better way to do this, if so, please let me know. Fixes #53312 ### Why? Currently, the error you get says `(0 , react__WEBPACK_IMPORTED_MODULE_1__.experimental_useOptimistic) is not a function or its return value is not iterable`. This is misleading. <img width="1043" alt="Screenshot 2023-07-28 at 3 30 10 PM" src="https://github.com/vercel/next.js/assets/12662580/ee16fd84-633d-47a1-8db4-cfc050546614"> ### How? Adds `experimental_useOptimistic` to the lists of forbidden imports. Adds some specific tests around this, but I'm not sure they're necessary, looking at how the other tests are written. Co-authored-by: Zack Tanner <1939140+ztanner@users.noreply.github.com>
Author
Parents
Loading