next-translate icon indicating copy to clipboard operation
next-translate copied to clipboard

Dynamic pages take too long to open

Open Denys-Oleksiienko opened this issue 3 years ago • 3 comments

What version of this package are you using?

"next": "^12.3.4", "next-translate": "^2.0.5", "react": "^17.0.2", "next-translate-plugin": "^2.0.5"

What operating system, Node.js, and npm version? MacOs: 13.3.1 Node: 18 npm v8.19.3

What happened? I've updated next-translate from version 1.0.5 to 2.0.5. On vercel when deploying the project with the new version next-translate, the dynamic pages like [id].js are very long open the first time. For example: src/pages/users.tsx src/pages/users/[userId].tsx

next-translate - compiled page: /users - locale: en - namespaces: translation - used loader: getStaticProps next-translate - compiled page: /users/[userId] - locale: en - namespaces: translation - used loader: getServerSideProps

There my next.config.js:

const nextTranslate = require('next-translate-plugin');
module.exports = nextTranslate({
  webpack: (config, options) => {
    //....
    return config;
  },
});

middleware.ts

import { NextResponse, NextMiddleware } from 'next/server';

const PUBLIC_FILE = /\.(.*)$/;
export const middleware: NextMiddleware = (req) => {
  const acceptLanguage =
    req?.headers?.get('accept-language') &&
    req?.headers?.get('accept-language')?.slice(0, 2);

  if (
    req.nextUrl.pathname.startsWith('/_next') ||
    req.nextUrl.pathname.includes('/api/') ||
    PUBLIC_FILE.test(req.nextUrl.pathname)
  ) {
    return;
  }

  if (req.nextUrl.locale === 'default') {
    const newUrl = req.nextUrl.clone();
    newUrl.locale = acceptLanguage || 'en';
    return NextResponse.redirect(newUrl);
  }
};

What did you expect to happen?

Dynamic pages open quickly as usual before the update.

Denys-Oleksiienko avatar Apr 22 '23 09:04 Denys-Oleksiienko

Would be great if you create a reproducible example in a repo 😊 in this way we can investigate if this problem is related to the next-translate library or not. Thanks!

aralroca avatar Apr 26 '23 13:04 aralroca

I'm having the same issue, for some reason it takes ages to load

simonpeters avatar Jun 13 '23 12:06 simonpeters

Try:

(requires Next.js 13)

aralroca avatar Jun 16 '23 14:06 aralroca