Comments (8)
As commented in another issue, I released 1.11.0-5 to fix the issue. I hope it works now, but I had to drop the support old next versions (<13.5.0)...
As for this HEAD request, it is a Next issue, filed here. You can thumb up the issue.
from next-translate-routes.
We have noticed a similar issue, or likely the same issue.
For us it can be reproduced in any production build.
With some static pages, client side navigation will result in a failed HEAD
request (404) in a similar manner as stated in the issue description. It seems that the issue takes places on static pages that use next-translate-routes
for translating pathnames (with some further details at the end of the message).
(GET) /_next/data/[hash]/[locale]/file-path-name.json ✅
(HEAD) /_next/data/[hash]/[locale]/translated-name.json ❌
(GET) /_next/data/[hash]/fr/coffee-shops.json ✅
(HEAD) /_next/data/[hash]/fr/cafes.json ❌
I'm not fully certain where the HEAD request is fired from or why, but I suspect that it has to do with Nextjs' router trying to sniff some details about the page we are navigating into.
We are using next version 13.2.4. The HEAD
request is probably configured in this function:
https://github.com/vercel/next.js/blob/05f6de10869021dbb6124e174778e2108c9b4e8e/packages/next/src/shared/lib/router/router.ts#L497
Here's an example from our .next/server/pages
for the coffee shops
page. The language used for folder and file names under pages
is en
, but fr
is used as the default and only locale.
// .next/server/pages
pages/
├─ fr/
│ ├─ coffee_shops.json
│ ├─ coffee_shops.html
│ ├─ coffee_shops/
│ │ ├─ cafe-armand.json
│ │ ├─ cafe-armand.html
├─ coffee_shops/
│ ├─ [slug].json
├─ coffee_shops.json
If I configure the application to support en
, I do not get HEAD 404 errors when that locale is selected (likely because it matches with the file langauge inside pages
.
Curiously while
(HEAD) /_next/data/[hash]/fr/cafes.json ❌
fails, the following example does not fail:
(HEAD) /_next/data/[hash]/fr/cafes/cafe-armand.json?slug=cafe-armand ✅
from next-translate-routes.
@Viktor-as @Jokinen I'm facing the same issue as you're describing when deploying to Vercel. By any chance, did you guys manage to solve this?
from next-translate-routes.
@Viktor-as @Jokinen I'm facing the same issue as you're describing when deploying to Vercel. By any chance, did you guys manage to solve this?
Hey @NSpehler , well I found some workaround for this. In src/pages/_app.tsx I have this code:
const App = ({ Component, pageProps }: AppProps) => {
if (typeof window === 'object') {
const { fetch: originalFetch } = window;
const nextDataRequestRegex =
/\/_next\/data\/[^/]+\/[^/]+\/([^/]+)(?!\.json)\/?/;
window.fetch = async (...args) => {
const [url] = args;
const match = url.toString().match(nextDataRequestRegex);
if (match) {
const word = match[1];
const cleanedWord = word.replace(/\.json$/, '');
if (excludeArray.includes(cleanedWord)) {
return Promise.reject();
}
}
return originalFetch(...args);
};
}
return ( ...
this intercepts and prevents those unnecessary fetches.
Lets say Next tries to fetch this URL /_next/data/ZAjS6fXQOKhw0BLn1dIOk/lt/kontaktai.json
const word will be kontaktai.json
then const cleanedWord will be kontaktai
excludeArray is an array of my pages translations that I do not want to unnecessary fetch, like ['kontaktai', ...]
so when the fetch matches my words (page translations) in excludeArray the fetch is rejected
from next-translate-routes.
Would any of you test with [email protected]
? I added something that may fix your problem...
from next-translate-routes.
@cvolant that version gives an error. I tried 0-2 and 0-3. App crashes on load.
from next-translate-routes.
Yes, I also saw that 1.11.0-0 crashes in some configs. That is why I tried with different solutions up to 1.11.0-3, but still no luck. I will tell you as soon as I get a working version. I hope I will find some time to work on this soon.
from next-translate-routes.
The issue happens to me on 1.11.0-5 and next 14.2.3 on Vercel on server side generated pages when I navigate to them via next/router. Directly accessing it works fine. Also static pages work fine.
from next-translate-routes.
Related Issues (20)
- Add support for Next 13 `/app` directory HOT 4
- Update LinkProps to support Next.js 13 <Link> component HOT 2
- Update pagesDirs to support Next.js 11 pages path HOT 1
- Next Link supports ref, but next-translate-routes does not HOT 1
- Routing does not work any more after update to next 13.3.0 HOT 7
- Add the ability to export the translations directly from the pages HOT 1
- How can I use it in storybook? HOT 1
- Static segment after dynamic segment? HOT 2
- How to work with dynamic routes? HOT 1
- The page could not be found on refresh HOT 2
- Mailto links are broken since v.1.9.2 HOT 1
- The querystring API is considered Legacy
- Error: spawn E2BIG when running in Docker HOT 19
- Module not found: Can't resolve 'next/dist/shared/lib/router-context' HOT 3
- Redirection issue using getServerSideProps HOT 2
- codesandbox link in readme isn't working
- Module not found: Can't resolve 'next/dist/shared/lib/router-context' HOT 8
- I'm using [email protected] with pages router, but still getting the "does not support `/app` directory yet." error HOT 1
- I am using [email protected] (Pages router) and when I compile appear this error "Can't resolve 'next/dist/shared/lib/router-context'"
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-translate-routes.