Company logo
  • Empleos
  • Bootcamp
  • Acerca de nosotros
  • Para profesionales
    • Inicio
    • Empleos
    • Cursos y retos
    • Preguntas
    • Profesores
    • Bootcamp
  • Para empresas
    • Inicio
    • Nuestro proceso
    • Planes
    • Pruebas
    • Nómina
    • Blog
    • Calculadora

0

60
Vistas
Nextjs Incremental Static Generation, cache clear

I have an issue with using incremental static generation with Nextjs framework, I am using getStaticPath and getStaticProps As the following code

export const getStaticPaths: GetStaticPaths = async () => {
const paths = [{ params: { username: 'kelly' } }];

return {
    paths,
    fallback: true
};
};

export const getStaticProps: GetStaticProps = async (context: any) => {
    const username = context.params.username;
    /* api call getUserData */
    const userData = await getUserData(username);
    if (!userData || userData.images.length < 1) {
        return {
            notFound: true
        };
    }

    return {
        props: {
            userData
        },
        revalidate: 300
    };
};

Everything works fine as expected
if i update the user endpoint api, the user page gets updated , and using fallback = true, the page is rebuilt every 300s , so all is good here.

the problems begin if i delete a user ( example user1) , (in my case when the api endpoint is rendering no data for user1). The page that has the path (/myapp/user1 ) should give a 404 as expected in the code instead of that -I am getting a 404 page for only 20min, then the 404 page is replaced by a cached page (seems to be the latest static page that nexts has built for this path)

it looks like for Nextjs, as long as a static page has already been built for a given path myapp/user1, if later this page no longer exists (404 or redirect404), Nextjs will serve the page it has in the cache (the latest page that was built),

The only way I found to remove the static page and get the 404 for the page, is to redeploy (to perform a rebuilt npm run build)

Please help: -Is there an option to change this cache config in nextjs, if yes how and where / -Is it a lack of option for Nextjs when using Incremental static generation ? -also for unknown reason it works fine on stage but on production it s not working.

7 months ago · Juan Pablo Isaza
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar empleo Planes Nuestro proceso Comercial
Legal
Términos y condiciones Política de privacidad
© 2023 PeakU Inc. All Rights Reserved.