Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

before sending html, check if response is still open #229

Closed
wants to merge 1 commit into from
Closed

before sending html, check if response is still open #229

wants to merge 1 commit into from

Conversation

bhurlow
Copy link

@bhurlow bhurlow commented Nov 8, 2016

current with next if you try something like this:

export default class Foo extends React.Component {

  static getInitialProps ({ req, res }) {

   // manually override server side react rendering 
    if (req) {
        res.end('my hijacked response!');
        return {}
    }
    return {}
  }

  render() {
    return <h1> Hi </h1>
  }
}

next will attempt to write rendered html to the now closed http response which results in a "can't set headers after they've been sent" error.

This PR checks to see if the response is still open before sending html, allowing for more adhoc hijacking of the request in getInitialProps

@rauchg
Copy link
Member

rauchg commented Nov 9, 2016

The best way to hijack will be #25, so that rendering the component is not attempted at all

@bhurlow
Copy link
Author

bhurlow commented Nov 9, 2016

cool! agreed, better to not render at all if req/res is intercepted

@bhurlow bhurlow closed this Nov 9, 2016
@lock lock bot locked as resolved and limited conversation to collaborators Jan 19, 2019
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.

2 participants