Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: don't rewrite Next.js server actions' requests #1707

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

agurtovoy
Copy link

What/Why?

Behind the scenes, Next.js server actions are translated into POST requests that get handled by the framework. withRoutes middleware was intercepting and rewriting these requests as page renders.

Copy link

changeset-bot bot commented Dec 5, 2024

⚠️ No Changeset found

Latest commit: d84b273

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

This PR includes no changesets

When changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types

Click here to learn what changesets are, and how to add one.

Click here if you're a maintainer who wants to add a changeset to this PR

Copy link

vercel bot commented Dec 5, 2024

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
catalyst-latest ✅ Ready (Inspect) Visit Preview 💬 Add feedback Dec 5, 2024 1:25am
catalyst-soul ✅ Ready (Inspect) Visit Preview 💬 Add feedback Dec 5, 2024 1:25am
3 Skipped Deployments
Name Status Preview Comments Updated (UTC)
catalyst ⬜️ Ignored (Inspect) Dec 5, 2024 1:25am
catalyst-au ⬜️ Ignored (Inspect) Dec 5, 2024 1:25am
catalyst-uk ⬜️ Ignored (Inspect) Dec 5, 2024 1:25am

Copy link
Contributor

github-actions bot commented Dec 5, 2024

⚡️🏠 Lighthouse report

Lighthouse ran against https://catalyst-latest-pjk5b3na6-bigcommerce-platform.vercel.app

🖥️ Desktop

We ran Lighthouse against the changes on a desktop and produced this report. Here's the summary:

Category Score
🟢 Performance 94
🟢 Accessibility 96
🟢 Best practices 100
🟠 SEO 82

📱 Mobile

We ran Lighthouse against the changes on a mobile and produced this report. Here's the summary:

Category Score
🟠 Performance 89
🟢 Accessibility 96
🟢 Best practices 100
🟠 SEO 85

node: z.infer<typeof NodeSchema> | null | undefined,
request: NextRequest,
postfix: string,
) => {
Copy link
Author

@agurtovoy agurtovoy Dec 5, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Factored out a standalone piece of logic from withRoutes below to keep the withRoutes complexity under the limit. No semantic changes. I kept RawHtmlPage handling in withRoutes as a special case that is separate from the rewrite logic.

diff


if (!request.nextUrl.search && !customerAccessToken && request.method === 'GET') {
postfix = '/static';
}
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Moved below.

// https://nextjs.org/docs/app/building-your-application/data-fetching/server-actions-and-mutations#behavior
if (isServerAction(request)) {
return next(request, event);
}
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The actual fix.

@agurtovoy agurtovoy marked this pull request as ready for review December 5, 2024 01:45
@agurtovoy agurtovoy requested a review from a team as a code owner December 5, 2024 01:45
@agurtovoy agurtovoy marked this pull request as draft December 5, 2024 01:56
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants