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

Remove react-hot-loader #4500

Merged
merged 12 commits into from May 31, 2018

Conversation

timneutkens
Copy link
Member

@timneutkens timneutkens commented May 30, 2018

Fixes #4494

@timneutkens timneutkens changed the title [WIP] Remove react-hot-loader Remove react-hot-loader May 30, 2018
// Since componentDidMount doesn't handle errors we use then/catch here
applySourcemaps(error).then(() => {
this.setState({mappedError: error})
}).catch(console.error)

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe here we can set this.state.mappedError to the error from applySourcemaps, or atleast set the error to something like "Couldn't render error. Check console for additional debugging details".


export type RuntimeError = {
...Error,
module: ?{

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I highly recommend using {| ... |} over { ... } when possible. I'm not sure if possible here?

export type Info = null | ComponentDidCatchInfo

export type RuntimeError = {
...Error,

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also, Use intersection types:

Copy link

@pranaygp pranaygp May 30, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

export type RuntimeError = Error & {module: ?{| rawRequest: string |}}

client/index.js Outdated
renderReactElement(<App {...appProps} />, appContainer)
let onError = null

if (process.env.NODE_ENV === 'production') {
Copy link

@pranaygp pranaygp May 30, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

how about process.env.NODE_ENV !== 'development'

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Seems safer to me to fail over to "pretty-printing" an error

@@ -7,6 +7,7 @@ import { loadGetInitialProps, getURL } from '../lib/utils'
import PageLoader from '../lib/page-loader'

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

possible to // @flow this or should we do that in a later PR (i.e. PR just to flowtype more things)

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, I didn't on purpose, carefully chose which files to start with 👍

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

lib/app.js Outdated
}
// Kept here for backwards compatibility.
componentDidCatch (err) {
throw err

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

wish we could get rid of this, but oh well. Much cleaner 😍

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure how we're going to deprecate this correctly, we can't warn since it's triggered in normal cases where an error is thrown too. I'm guessing we should just include it in the release notes / blogpost of Next 7.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Doesn't componentDidCatch implicitly just throw err upwards anyway? I haven't used Error Boundaries, but from reading the release I understood that this works similar to context and it'll just bubble up.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What's the purpose of the explicit componentDidCatch?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's backward compatibility, with the current implementation we told people to do this:

componentDidCatch(err, info) {
  console.log('YOUR OWN LOGGING')
  super.componentDidCatch(err, info)
}

And since React.Component doesn't implement the method we can't let it fall back on that.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This applies when using a custom pages/_app.js that overrides this file and extends the App class.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

oh I see! They should also be able to:

Copy link

@pranaygp pranaygp May 30, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

componentDidCatch(err, info) {
  console.log('YOUR OWN LOGGING')
  throw err
}

right?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

With the new solution, it can be easily done "the React way" by just throwing the error up the bubble, eg:

componentDidCatch(err, info) {
  console.log('YOUR OWN LOGGING')
  throw err
}

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🎉

Copy link

@pranaygp pranaygp left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@timneutkens timneutkens merged commit 86d0170 into vercel:canary May 31, 2018
@timneutkens timneutkens deleted the fix/remove-react-hot-loader branch May 31, 2018 09:47
lependu pushed a commit to lependu/next.js that referenced this pull request Jun 19, 2018
@lock lock bot locked as resolved and limited conversation to collaborators May 31, 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.

Remove react-hot-loader
2 participants