next.js
056c57bd - fix: only set request phase to "action" when actually running an action (#76993)

Commit
287 days ago
fix: only set request phase to "action" when actually running an action (#76993) When running a server action, we want `requestStore.phase` to be set to `'action'`, because it makes `cookies()` mutable. However we were doing this in a pretty coarse-grained manner -- it was set at the beginning of `handleAction`, but wasn't always properly cleaned up in case of early returns that don't render anything (e.g. `{ type: 'not-found' }`). This PR fixes that -- we only set the phase to `'action'` while the action is running, and immediately switch it to `'render'` when it settles. Incidentally, early 'not-found' returns from `handleAction` are currently bugged (see https://github.com/vercel/next.js/pull/77012 for more context + fix), so we were also accidentally allowing mutatating cookies while rendering a response to an unrecognized action, which should be a 404, but is currently a 200 + a page render. but that's such a niche edge case that it's not really relevant to real usage.
Author
Parents
Loading