Comments (16)
Hello, Rahul.
Just tried to run your code and, apparently, the error does not occur on my machine (i dont know why)
from next.js.
@ztanner Works on my project, thanks a lot!
from next.js.
@caioalmeida12 That's because you ran localhost:3000/test without adding the subdomain in front. As per my reproduction steps you need to navigate to demo.localhost:3000/test. I will update the repo to return 404s without subdomain
from next.js.
Check your network panel for a CORS error. Having a request/response mysteriously zero itself out is a smell that usually points to a CORS violation, as the browser will ditch the body of the request without any other indication that something went wrong.
from next.js.
@dfltr Route handlers work though and don't see anything, does the code work when you run it locally?
from next.js.
Update on this: regular server actions used in
elements return undefined as well even though the action is being performed. This is a pretty critical bug hope it can be resolved or touched uponfrom next.js.
It looks like your middleware is rewriting the IPC call that powers the server action on the /test
page. The fetch
call associated with your server action is only bundled with the /[domain]/test
route and it's being rewritten to /localhost:3000/[domain]/test
.
I'm not 100% following your middleware logic but you can avoid rewriting the action handlers by ensuring the rewrite isn't called for requests that contain the next-action
header.
from next.js.
Ahhh that makes sense, thank you @ztanner for the quick response!
What Im trying to do in the middleware is take any subdomain request like test.localhost:3000/ and in the middleware add the domain as a slug that I can use to support multi tenancy. Majority of this middleware code is from the Vercel Platforms Starter Kit. I think this is something that needs to be addressed in the starter kit then since server actions come undefined there as well.
Would there be another way you'd suggest to go about this?
from next.js.
Hey @ztanner, can't get redirects within server actions to work even though Im excluding it on the middleware. If I put an absolute url in the redirect as well it'll show a 404 and then upon refresh go to the right place :/ It seems like redirects also include the next-action header so when I exclude it, it doesn't do the redirection properly.
from next.js.
Hey @RahulBirCodes -- I took a closer look and realized the rewrite actually isn't the inherent problem, so you can ignore that suggestion. I think what's happening is that the middleware is causing the content-type header that we would normally set on the action to get lost on the response. Could you try something like this in your middleware and let me know if it works for you?
if (req.headers.get('next-action')) {
newHeaders.set('content-type', 'text/x-component')
}
(I don't expect this to be something you have to worry about in your code, just wanting to identify the root cause)
from next.js.
Hey @ztanner, just tested and got the following error on the client: ⨯ SyntaxError: No number after minus sign in JSON at position 1 (line 1 column 2)
at JSON.parse ()
digest: "837905482"
from next.js.
Hey @ztanner, just tested and got the following error on the client: ⨯ SyntaxError: No number after minus sign in JSON at position 1 (line 1 column 2) at JSON.parse () digest: "837905482"
Does that happen in your repro, or do you have different code that's causing that behavior? If so could you update your repro?
from next.js.
@ztanner just pushed to my repro. It's throwing the json error as well now. i updated it to mimic my actual project a little bit so when you're testing go to demo.localhost:3000/login instead.
from next.js.
@ztanner just pushed to my repro. It's throwing the json error as well now. i updated it to mimic my actual project a little bit so when you're testing go to demo.localhost:3000/login instead.
Thanks for the repro. I've traced it to when you attempt to pass new headers into NextResponse.rewrite
. If you don't override the rewrite headers it appears to function properly. I'll dig in on the Next.js side to see why that's happening.
from next.js.
Hey @RahulBirCodes upon digging further into it, I think this is expected behavior.
In your reproduction you're taking request headers, adding a new property, and then sending to the client as response headers. However those request headers aren't meant to be sent to the client, as they overwrite things like content-type etc.
If you're wanting to add the x-url
response header, you can do so on a new Headers object, rather than cloning the headers from the request. I confirmed that worked as expected, so I'm going to close this out!
from next.js.
This closed issue has been automatically locked because it had no new activity for 2 weeks. If you are running into a similar issue, please create a new issue with the steps to reproduce. Thank you.
from next.js.
Related Issues (20)
- AsyncLocalStorage accessed in runtime where it is not available HOT 1
- generateStaticParams validation makes react-router migrations difficult
- An error occurred in `next/font`. TypeError: Cannot read properties of undefined (reading 'ascent') HOT 1
- Scroll Position Issue When Changing Pages
- Compilation is slow HOT 1
- Server actions regression in 14.2.8: “Failed to find Server Action” HOT 13
- Not deployable out the gate
- Intercepting Routes - refresh when modal is open cannot go back to modal again unless another refresh HOT 1
- app router does not resolve routes according to `generateStaticParams` constraints HOT 9
- Invalid Metadata properties caused by Route Group and Parallel Route at the same Level HOT 1
- Setting a cookie in middleware & a server action results in duplicate Set-Cookie headers HOT 8
- NoFallbackError on 404 routes with pages router and middleware. HOT 1
- NoFallbackError on 404 routes with pages router and middleware. HOT 1
- Docs: The docs say Next.JS 14 supports experimental PPR but anecdotal evidence says otherwise HOT 1
- Debugging issue with Error Code SIGLL HOT 1
- Version info in error page shows different font sizes
- Debugging issue with Error Code SIGLL
- @next/swc-android-arm64 on build error HOT 1
- Server action in 18.2.6 vs 18.2.8 is not longer able to import server action in client component HOT 6
- With the `experimental-https` and `-H` options, the next dev will show a different URL
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from next.js.