Repository navigation
|
Hello. I've recently started learning and working with next.js, i've build a simple cpanel page, and it should get data on everytime the page is requested (like react's useEffect hook), so I tried using getServerSideProps, it worked fine on local dev server, but when i do npm run dev (which runs next build && next export), it starts building and then when it starts exporting it gives me this error: // /pages/index.js
import Layout from "../components/Layout/Layout.js";
import PanelWrapper from "../components/panel/panelWrapper.js";
import getEnrolls from "../components/fetch/fetch.js";
import { API } from "../exports/config.js";
const PanelPage = ({ all, pending, accepted }) => {
const [allEnrolls, setAllEnrolls] = React.useState(all);
const [pendingEnrolls, setPendingEnrolls] = React.useState(pending);
const [acceptedEnrolls, setAcceptedEnrolls] = React.useState(accepted);
const [status, setStatus] = React.useState("all");
const [allPage, setAllPage] = React.useState(allEnrolls.currentPage);
const [pendingPage, setPendingPage] = React.useState(
pendingEnrolls.currentPage
);
const [acceptedPage, setAcceptedPage] = React.useState(
acceptedEnrolls.currentPage
);
//some functions in here
return (
<Layout>
<PanelWrapper
all={allEnrolls}
pending={pendingEnrolls}
accepted={acceptedEnrolls}
/>
</Layout>
);
};
export const getServerSideProps = async () => {
const { all, pending, accepted } = await getEnrolls();
return {
props: {
all,
pending,
accepted,
},
};
};
export default PanelPage; |
Replies: 4 comments 5 replies
|
Yes, this is a very limitating issue for us. Maitaining both server render and static export is important to us, as it allows optimization on the fly when SSR becomes too costly or the SSR version has issues for some reason. Issuing a warning would make sense (so user are not surprised that he server side props function doesn't run), instead of an error. |
|
@salahmak you however seem to confuse static export with dynamic server side rendering. When running |
|
@salahmak with your example, you should switch |
|
well guys, i forgot to close this issue after solving it, the thing is, i was trying to export a page that has getServerSideProps in it. |
well guys, i forgot to close this issue after solving it, the thing is, i was trying to export a page that has getServerSideProps in it.
exporting is meant for pages that are static and not SSR, so the solution was to just build the pages and host them directly without exporting. Thanks everyone