Skip to content
This repository was archived by the owner on May 10, 2021. It is now read-only.
This repository was archived by the owner on May 10, 2021. It is now read-only.

Page chunk for catch-all page at root level is evaluated/rendered on the server #43

Closed
@Yegair

Description

@Yegair

Hello,

First of all thanks for the great work with next-on-netlify, highly appreciated!


What is wrong?

If have a custom app which makes use of SSR via getInitialProps.

pages/_app.jsx:

import React from 'react';
import App from 'next/app';

const MyApp = ({ Component, pageProps, ...customProps }) => {
    return <Component {...pageProps} {...customProps} />;
};

// having a custom app with getInitialProps forces all pages to be rendered on the server
MyApp.getInitialProps = async (ctx) => {
    const appProps = App.getInitialProps(ctx);
    return {
        ...appProps,
        somePropFrom_app: "Hello from the _app"
    };
};

export default MyApp;

Also I have a catch-all page which is used as the index page and as a fallback if there is no matching page for the current route (obviously).

pages/[[...any]].jsx:

import React, { useEffect, useState } from 'react';

export default ({ somePropFrom_app }) => {
    const [ someState, setSomeState ] = useState('waiting for client side code execution...');

    useEffect(() => {
        setSomeState('client side code was executed properly!')
    });

    return (
        <main>
            <p>{somePropFrom_app}</p>
            <p>{someState}</p>
        </main>
    )
}

When I access the catch-all page it is being rendered on the server correctly, but the client side rendering fails. It seems the server sends the rendered HTML instead of the JS source code when the frontend fetches the static JS chunk for this page.

console

When I look at the network tab, I can see that the browser tried to fetch the JS chunk, but received fully rendered HTML instead:

network

As far as I could test it, this seems not to happen for catch-all pages within subdirectories. For example
pages/foo/[[...any]].jsx works as expected.

How to reproduce?

I have set up a minimal repository which reproduces the issue: https://github.com/Yegair/next-on-netlify-minimal.
You can also have a look at the running example here: https://condescending-allen-4992da.netlify.app/

Are there related issues?

This issue may be related to #41 (at least the workaround is the same).

Is there a Workaround?

As I said above, the Workaround from #41 seems to resolve the issue.
Just add a "No-Op redirect" for the /_next/* route:

_redirects:

/_next/* /_next/:splat 200

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions