Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

getServerSideProps returns an empty object when using next/link and a middleware. #3704

Closed
5 tasks done
FacundoSpira opened this issue Sep 14, 2023 · 7 comments
Closed
5 tasks done
Assignees
Labels
archived This issue has been locked. bug Something isn't working compute

Comments

@FacundoSpira
Copy link

Before opening, please confirm:

  • I have checked to see if my question is addressed in the FAQ.
  • I have searched for duplicate or closed issues.
  • I have read the guide for submitting bug reports.
  • I have done my best to include a minimal, self-contained set of instructions for consistently reproducing the issue.
  • I have removed any sensitive information from my code snippets and submission.

App Id

d3g9j0bpx2nsb4

AWS Region

us-east-1

Amplify Hosting feature

SSR

Frontend framework

Next.js

Next.js version

13.4.2

Next.js router

Pages Router

Describe the bug

I created a simple Next.js application. Inside I have some pages that use SSR (with getServerSideProps) and I have an empty middleware (it just returns NextResponse.next()).

The different pages are pretty simple, just containing a getServerSideProps and printing the content of that on the screen:

import type { InferGetServerSidePropsType } from 'next';
import Link from 'next/link';

type HomeProps = InferGetServerSidePropsType<typeof getServerSideProps>;

const Home = (props: HomeProps) => {
  return (
    <main>
      <div>
        <Link href="/">Home</Link>
        <Link href="/page1">Page 1</Link>
        <Link href="/page2">Page 2</Link>
      </div>

      <h1>Server Side Props</h1>
      <pre>{JSON.stringify(props, null, 2)}</pre>
    </main>
  );
};

export const getServerSideProps = () => {
  return {
    props: {
      page: 'Home',
    },
  };
};
export default Home;

The issue is than randomly when navigating through the links, getServerSideProps return an empty object. That behaviour can be seen on the following video and it appears to happen when we start navigating "too fast":

Screen.Recording.2023-08-18.at.16.27.08.mov

This only happens when we use next/link, a middleware file and getServerSideProps at the same time.
I created a minimal reproducible example on the following repository: https://github.com/FacundoSpira/amplify-nextlink-middleware-error
And the app is deployed here: https://main.d3g9j0bpx2nsb4.amplifyapp.com/

Expected behavior

The app should navigate correctly, regardless of how many times and how quickly I click on a link.

Reproduction steps

  1. Clone the repository: https://github.com/FacundoSpira/amplify-nextlink-middleware-error
  2. Deploy it to amplify
  3. Navigate to the deployed URL and start navigating between the links. When navigating too quickly getServerSideProps will return an empty object.

Build Settings

No response

Log output

No response

Additional information

No response

@Jay2113
Copy link
Contributor

Jay2113 commented Oct 5, 2023

Hi @FacundoSpira 👋 , thanks for raising this and for sharing detailed reproduction steps.

I was able to reproduce the behavior where getServerSideProps returned an empty object when quickly navigating through the links. I am investigating into this further and will keep you posted with any updates.

@FacundoSpira
Copy link
Author

Hi @FacundoSpira 👋 , thanks for raising this and for sharing detailed reproduction steps.

I was able to reproduce the behavior where getServerSideProps returned an empty object when quickly navigating through the links. I am investigating into this further and will keep you posted with any updates.

Thanks! Glad you were able to reproduce it. Please let me know if there's anything we can help with.

@FacundoSpira
Copy link
Author

Hello @Jay2113, hope you are doing well.
Is there any update on the issue?
Thanks!

@Jay2113
Copy link
Contributor

Jay2113 commented Feb 22, 2024

@FacundoSpira 👋 , apologies for the delayed response here. We have identified this as a bug and are actively working to mitigate it. I'll keep you posted with any updates.

@Jay2113
Copy link
Contributor

Jay2113 commented Jul 25, 2024

We have deployed a fix for this issue.

@Jay2113 Jay2113 closed this as completed Jul 25, 2024
Copy link

This issue is now closed. Comments on closed issues are hard for our team to see.
If you need more assistance, please open a new issue that references this one.

Copy link

This issue has been automatically locked.

@github-actions github-actions bot added the archived This issue has been locked. label Jul 25, 2024
@github-actions github-actions bot locked and limited conversation to collaborators Jul 25, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
archived This issue has been locked. bug Something isn't working compute
Projects
None yet
Development

No branches or pull requests

2 participants