Comments (9)
@amannn We figured it out: We called useLocale
in serverside code which - for some reason - used to work fine before 3.14 but now throws an error. Now we're using await getLocale()
and everything works fine again. 👍🏼
from next-intl.
A reproduction would be important to look into this, but based on the stack trace, it could be that your error is caused by this misconfiguration: Unable to find locale. You should see an error message pointing towards this on the console though.
from next-intl.
I also currently can't provide a lot of information but we just had to hotfix rollback next-intl from 3.14.0 to 3.13.0 as a big part of our app (NextJS, App Router, RSC, TRPC) was completely broken:
Frontend:
Error: An error occurred in the Server Components render. The specific message is omitted in production builds to avoid leaking sensitive details. A digest property is included on this error instance which may provide additional details about the nature of the error.
Backend:
a [TRPCClientError]: Suspense Exception: This is not a real error! It's an implementation detail of `use` to interrupt the current render. You must either rethrow it immediately, or move the `use` call outside of the `try/catch` block. Capturing without rethrowing will lead to unexpected behavior.
To handle async errors, wrap your component in an error boundary, or call the promise's `.catch` method and pass the result to `use`
at a.from (/var/task/apps/web/.next/server/chunks/8292.js:1:1194)
at /var/task/apps/web/.next/server/chunks/8292.js:5:1545 {
meta: undefined,
shape: undefined,
data: undefined,
digest: '3877659871',
[cause]: Error: Suspense Exception: This is not a real error! It's an implementation detail of `use` to interrupt the current render. You must either rethrow it immediately, or move the `use` call outside of the `try/catch` block. Capturing without rethrowing will lead to unexpected behavior.
We've never had this issue before.
Rolling back to next-intl 3.13 fixed it immediately. (the only change we committed which fixed the issue)
Might me able to provide more information after Tuesday.
from next-intl.
Interesting. If you could provide some more information or ideally a reproduction, that would be helpful.
There was another report about 13.14, we were able to resolve that: #1072
from next-intl.
I can't provide a full reproducable example but maybe an excerpt of the code might help to show what we're using:
import { notFound, redirect, RedirectType } from "next/navigation";
import { getTranslations } from "next-intl/server";
import { api } from "~/trpc/server";
async function getData(id: string) {
try {
return await api.getData.query({
id,
});
} catch (error) {
// this had some more logic to check for a not found error in this case we called "notFound()"
throw error;
}
}
export default async function Page({
params,
}: {
params: { id: string };
}) {
const { id } = params;
const data = await getData(id);
if (data.isComplete) {
redirect("/different/path", RedirectType.replace);
}
const t = await getTranslations();
return <div>// ... component that uses t</div>;
}
This code never resulted in any problems before upgrading to 3.14
Thanks for taking a look!
Let me know if I can provide anything else that might be of help
from next-intl.
I don't see an issue with that code. Can you try to isolate the issue to a particular line that causes the issue? Can you also post your i18n.ts
?
from next-intl.
My application works in the following way. I have two locales "default", "ru". In case the user has changed the locale, I use it the next time he visits the site (I use a cookie to switch the locale before rendering in the middleware file). Here is my middleware.ts file
import createIntlMiddleware from "next-intl/middleware";
import { NextRequest, NextResponse } from "next/server";
export default async function middleware(request: NextRequest) {
const handleI18nRouting = createIntlMiddleware({
locales: ["default", "ru"],
defaultLocale:
request.cookies.get("lang")?.value &&
request.cookies.get("lang")?.value == "ru"
? "ru"
: "default",
localePrefix:
request.cookies.get("lang")?.value &&
request.cookies.get("lang")?.value == "ru"
? "always"
: "as-needed",
localeDetection: false,
});
const response = handleI18nRouting(request);
const locale =
response.headers.get("x-middleware-request-x-next-intl-locale") ||
"default";
response.cookies.set("lang", locale == "default" ? "az" : locale, {
expires: new Date(new Date().getTime() + 90 * 24 * 60 * 60000),
});
return response;
}
export const config = {
matcher: ["/((?!_next|.*\\..*).*)", "/([\\w-]+)?/profile/(.+)"],
};
Here is my i18n.ts file:
import { notFound } from "next/navigation";
import { getRequestConfig } from "next-intl/server";
const locales = ["default", "ru"];
export default getRequestConfig(async ({ locale }) => {
if (!locales.includes(locale as any)) notFound();
return {
messages: (await import(`../messages/${locale}.json`)).default,
};
});
from next-intl.
@ilikali Were you able to figure out a solution eventually?
"default" is in any case not a valid locale. The locale is not only used for reading messages, but also for formatting dates, etc.
I'm wondering why you have to do these gymnastics in the middleware? It seems like what you need is localePrefix: 'as-necessary'
, why can't you declare the two locales your app supports in the regular way, as it's shown in the docs and examples?
from next-intl.
@amannn I’ll try to explain why I’m facing such a dilemma. The fact is that my website uses two locales: Azerbaijani and Russian. However, the site also has pages that start with "/az", meaning "/az/[slug]" - where "az" is not a locale in the URL of the page. Therefore, I had to rename the "az" locale to "default", and then use code to check if the "default" locale is selected to simulate a call to the "az" locale. I understand this sounds very complex, but these are the realities of my project.
from next-intl.
Related Issues (20)
- Support `localePrefix` setting per domain HOT 2
- Support Intl.RelativeTimeFormat for `relativeTime` formatting HOT 3
- Docs Invisible Text on Search HOT 1
- Package path ./server.js is not exported from package HOT 2
- Error using `as={Link}` prop with when using `createSharedPathnamesNavigation` HOT 1
- Accidentally changed the locale after navigating when setting "localePrefix" to "never" HOT 2
- I cannot understand how to merge next-intl middleware with nextjs/platform HOT 3
- Official app router example: TypeError: Cannot read properties of undefined (reading 'en') HOT 1
- Error in 13.14.0: Expected a suspended thenable HOT 5
- [Docs]: Middleware matcher with Next-Auth HOT 1
- With i18n routing doesn't work with Next Canary (React 19) HOT 12
- Error: The React APIs of next-intl are currently not available in Server Components. HOT 2
- Route /en/xxx with `dynamic = "error"` couldn't be rendered statically because it used `headers` HOT 2
- Lazy-load intl-messageformat HOT 3
- Error: Insufficient params provided for localized pathname. HOT 1
- Link doesn't allow on production env HOT 1
- Integration with multi-tenancy HOT 10
- next-intl pages error (TypError) HOT 1
- Strict typing of global formats
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-intl.