next.js
b2f9fa45 - Fix: Rules of Hooks violation in AppRouter (#80623)

Commit
223 days ago
Fix: Rules of Hooks violation in AppRouter (#80623) There's some sketchy logic in AppRouter that (intentionally) violates the rules of hooks by reading an externally mutable condition. The rationalization is that it's OK to do this if the result is to infinitely suspend the component. However, the mechanism used to infinitely suspend the component is `use(infinitePromise)` — this can lead to subtle bugs because even though `use` can be called conditionally, it relies on the assumption that its invocation is idempotent for the same props and state, i.e. you must still follow the rules of React regarding mutability and side effects. Ideally we should refactor this block to not rely on external state at all, but in the meantime, we can switch from `use` to `throw` to suspend the component, since `throw` is lower level and isn't modeled as a hook.
Author
Parents
Loading