InstantSearch & server side rendering : staticContext undefined in first time

Here is my server side rendering implementation… I use staticContext for passing props to my component, but it’s not work in the first render… How can I solve this problem?

Here the error…

17

My component file…

class Search extends Component {
  render() {
    console.log('this.props.staticContext', this.props.staticContext)
      return (
        <InstantSearch
          appId="xx"
          apiKey="xx"
          indexName="xx"
          searchState={this.props.staticContext.searchState}
          resultsState={this.props.staticContext.resultsState}
        >
          <SearchBox />
          <Hits hitComponent = {Item}/>
        </InstantSearch>
    );
  }
}

export default { component:Search, findResultsState };

my server.js file

const app = express()
app.use(express.static("public"));

app.get('*', async (req, res) => {
  const findRoute = matchRoutes(Routes, req.path).filter(({route}) => route.findResultsState)
  const promises  = findRoute.map(async ({route:{findResultsState, component}}) => {
    const searchState =   req.query
    const resultsState =  await findResultsState(component, {searchState})
    return {searchState, resultsState}
  })


  
return Promise
       .all(promises)
       .then(datas =>   {
         const arrayToObject = (array) => array.reduce((obj, item) => {
           return item
         }, {})
         let context = arrayToObject(datas)
         const appAsString = renderToString(
          <StaticRouter location={req.path} context={context}>
              <App />
          </StaticRouter>
          );
        res.send(
      `
      <!doctype html>
      <html>
        <body>
          <div id="root">${appAsString}</div>
          <script>window.__APP_INITIAL_STATE__ = ${JSON.stringify(arrayToObject(datas))}</script>
          <script src="/manifest.manifest.js"></script>
          <script src="/vendor.bundle.js"></script>
          <script src="./app.bundle.js"></script> <!-- this is the build of browser.js -->
        </body>
      </html>`
        );
    })
})

Do you mean that it’s working after a second request to your server?