Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Improper sequence of getInitialProps #1267

Copy link
Copy link
@kirill-konshin

Description

@kirill-konshin
Issue body actions

I have Redux and async actions in getInitialProps, but it will also produce same results w/o redux too.

If getInitialProps function is used for both page and custom _document.js, then the sequence is:

  1. Page - getInitialProps
  2. Page - getInitialProps dispatches an action
  3. store state is now { page: 'ok', doc: 'init' }
  4. MyDocument - getInitialProps
  5. Page - renders with `{ page: 'ok', doc: 'init' } that's the problem, render happens before _document's getInitialProps call
  6. MyDocument - getInitialProps dispatches an action
  7. store is now { page: 'ok', doc: 'ok' }
  8. MyDocument - renders with { page: 'ok', doc: 'ok' }

So it seems, that MyDocument.getInitialProps is executed on page render, but I think, that such custom lifecycle methods should be called in sequence, before render, let's say, Page then Doc, so that on render everything is consistent.

Master branch of https://github.com/kirill-konshin/next-redux-wrapper contains the example.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

      Morty Proxy This is a proxified and sanitized view of the page, visit original site.