You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I am using the experimental optional catch all route in order to handle a search feature on a small ads app.
Routes could be: /search => main search page /search/city/rootCategory/parentCategory /search/city/rootCategory/parentCategory/category
Due to the huge number of possible routes, I am attempting to use getStaticPaths with getStaticProps on the page /pages/search/[[...query]].js. The idea is to pre-build static pages for existing ads and use the fallback:true to have Nextjs handle new routes on demand.
The issue I am facing is that it seems that pageProps is not populated initially and that generates errors because of missing property. Namely the Layout component requires the categories props` which is passed on downstream.
Later on console.log show that the props are populated but then the error already went downstream.
Describe the bug
To Reproduce
The console.log on _app.js below will show empty pageProps initially:
import withReduxSaga from 'next-redux-saga';
import PropTypes from 'prop-types';
import Head from 'next/head';
import { ThemeProvider } from '@material-ui/core/styles';
import CssBaseline from '@material-ui/core/CssBaseline';
import wrapper from '../store/reduxWrapper';
import theme from '../styles/theme';
// eslint-disable-next-line no-unused-vars
import styles from '../styles/layout.css';
import 'react-quill/dist/quill.snow.css';
import Layout from '../components/layout';
function MyApp(props) {
console.log('my app props', props);
const { Component, pageProps } = props;
React.useEffect(() => {
// Remove the server-side injected CSS.
const jssStyles = document.querySelector('#jss-server-side');
if (jssStyles) {
jssStyles.parentElement.removeChild(jssStyles);
}
}, []);
return (
<>
<Head>
<title>My page</title>
<meta
name="viewport"
content="minimum-scale=1, initial-scale=1, width=device-width"
/>
</Head>
<ThemeProvider theme={theme}>
<CssBaseline />
<Layout categories={pageProps.categories}>
<Component {...pageProps} />
</Layout>
</ThemeProvider>
</>
);
}
MyApp.propTypes = {
Component: PropTypes.elementType.isRequired,
pageProps: PropTypes.object.isRequired,
};
export default wrapper.withRedux(withReduxSaga((MyApp)));
This discussion was converted from issue #14659 on June 28, 2020 18:59.
Heading
Bold
Italic
Quote
Code
Link
Numbered list
Unordered list
Task list
Attach files
Mention
Reference
Menu
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
Uh oh!
There was an error while loading. Please reload this page.
-
Bug report
I am using the experimental optional catch all route in order to handle a search feature on a small ads app.
Routes could be:
/search
=> main search page/search/city/rootCategory/parentCategory
/search/city/rootCategory/parentCategory/category
Due to the huge number of possible routes, I am attempting to use
getStaticPaths
withgetStaticProps
on the page/pages/search/[[...query]].js
. The idea is to pre-build static pages for existing ads and use thefallback:true
to have Nextjs handle new routes on demand.The issue I am facing is that it seems that
pageProps
is not populated initially and that generates errors because of missing property. Namely theLayout
component requires thecategories
props` which is passed on downstream.Later on console.log show that the props are populated but then the error already went downstream.
Describe the bug
To Reproduce
The
console.log
on_app.js
below will show emptypageProps
initially:The page
/pages/search/[[...query]].js
Expected behavior
pageProps
should be available on_app.js
from the start, which is the case on the homepage route.Screenshots
If applicable, add screenshots to help explain your problem.
System information
Additional context
Add any other context about the problem here.
Beta Was this translation helpful? Give feedback.
All reactions