I've noticed that deploys via SST to AWS getStaticProps data is undefined, when following a <Link>
With a stock Next.js app using the pages router, if I follow a link via <Link href='/test'>Test</Link> to this page, the data is undefined:
// src/pages/test/index.tsx
export default function Test({ data }: { data: any }) {
console.log('Text component rendered');
if (!data) {
return <div>No data</div>;
}
return (
<div>
<h1>Test</h1>
<p>Data: {JSON.stringify(data)}</p>
</div>
);
}
export const getStaticProps = async () => {
const res = await fetch('https://jsonplaceholder.typicode.com/posts/1');
const data = await res.json();
return {
props: {
data,
},
};
};
If I visit /test directly, I get data. This is only an issue on a deployed build and the pages router.
There was a Discord comment that this was fixed in OpenNext 3.5.0, but more recent versions of Next.js seem to break it again.
I get back undefined for data from Next 15.4.1 onwards with the current SST (3.17.10), which uses OpenNext 3.3.6. Works with 15.4.0. (15.4.1 release notes)