Skip to content

Add isServer prop to getInitialProps#425

Closed
jamiebuilds wants to merge 1 commit intovercel:masterfrom
jamiebuilds:isServer
Closed

Add isServer prop to getInitialProps#425
jamiebuilds wants to merge 1 commit intovercel:masterfrom
jamiebuilds:isServer

Conversation

@jamiebuilds
Copy link
Contributor

It would be nice to have a slightly more clear argument to tell you whether you're rendering from the client-side or server-side.

export default class extends React.Component {
  static getInitialProps ({ isServer }) {
    return isServer ? {...} : {...};
  }
  render () {...}
}

Opening this up to see how you feel about it.

@coveralls
Copy link

coveralls commented Dec 19, 2016

Coverage Status

Coverage increased (+2.5%) to 59.936% when pulling 0cfa81a on thejameskyle:isServer into 955f681 on zeit:master.

@nkzawa
Copy link
Contributor

nkzawa commented Dec 19, 2016

We didn't add isServer by design for now because:

  • it should be a value per environment (not per method call).
  • easy to define it if you need.

Additionally, I think generally feature detection would be better than detecting runtime environment.

@rauchg
Copy link
Member

rauchg commented Dec 19, 2016

Yeah, isServer is more of an environment setting. We could have import isServer from 'next/env' or sth along those lines in the future. Thanks @thejameskyle

@rauchg rauchg closed this Dec 19, 2016
@lock lock bot locked as resolved and limited conversation to collaborators Jan 19, 2019
ForsakenHarmony pushed a commit that referenced this pull request Jul 25, 2024
I didn't really understand this part of the code when I wrote this. The dynamic import is never an entrypoint, so we shouldn't treat it as evaluated. Note, the underlying chunk foo.js without the runtime code was always available. But, the client linked to the evaluated foo.js.eval.js, because I incorrectly marked the chunk group as an evaluated one.

Fixes #425
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants