-
-
Notifications
You must be signed in to change notification settings - Fork 15.3k
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
RFC: remove React Transform from examples #1455
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,3 @@ | ||
{ | ||
"presets": ["es2015", "react"], | ||
"env": { | ||
"development": { | ||
"presets": ["react-hmre"] | ||
} | ||
} | ||
"presets": ["es2015", "react"] | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,15 +1,43 @@ | ||
import 'babel-polyfill' | ||
import React from 'react' | ||
import { render } from 'react-dom' | ||
import ReactDOM from 'react-dom' | ||
import { Provider } from 'react-redux' | ||
import App from './containers/App' | ||
import configureStore from './store/configureStore' | ||
|
||
const store = configureStore() | ||
const rootEl = document.getElementById('root') | ||
|
||
render( | ||
<Provider store={store}> | ||
<App /> | ||
</Provider>, | ||
document.getElementById('root') | ||
) | ||
let render = () => { | ||
const App = require('./containers/App').default | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. What's wrong with leaving this as an ES2015 import? Is there a technical reason why this must be changed to an inline require? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. the loader spec is still a work in progress but webpack v2 understands the draft proposal, which allows inline (dynamic) imports using system loader, ie: // webpack v2
let render = () => {
System.import('./containers/App').then(App => {
const AppContainer = App.default
ReactDOM.render(
<Provider store={store}>
<AppContainer />
</Provider>,
rootEl
)
})
} There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The reason it’s an inline require is because we want to import the latest version after hot update. In Webpack 2, if we disable Babel modules transform, we will be able use a normal There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Also, There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Thanks @gaearon makes sense. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Please see the discussion: here's how to make it work with React Router. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I've been following the discussion about vanilla HMR and decided to use that approach when upgrading to webpack in my universal-dev-toolkit. I'm using If you want to add Redux into the toolkit, you can wrap the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Thanks @gaearon for the pointer and @stoikerty for the information. I'm still struggling to get this working - when updating a component, I either get the I suspect that what is happening is that there is no clear "include path" from my component up to the root component due to the way my app is structured, hence the I need to take a look at my setup in more detail and work out why this might be happening... not a big deal for now anyway, I'm sticking with class components and There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @tomduncalf If you provide a more comprehensive example where it doesn't work, say in a repo or a gist, I'm willing to have a look for you. It sounds like the component you're trying to update might be outside of the tree that is on the hot-reload path. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Thanks @stoikerty, that is my suspicion too - my structure is a little more complex than the examples, because I have split the application into separate modules (which are in essence individual single page applications, with their own entry point) but with common code for some parts. I will put together a minimal reproducible example when I have a moment, and it would be great to get your feedback if I am unable to get it working! Thanks |
||
ReactDOM.render( | ||
<Provider store={store}> | ||
<App /> | ||
</Provider>, | ||
rootEl | ||
) | ||
} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why not put the try-catch here and call There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ah, good call. My goal was to make sure RedBox doesn't get into the production build but I can put some more conditionals to ensure that. |
||
|
||
if (module.hot) { | ||
// Support hot reloading of components | ||
// and display an overlay for runtime errors | ||
const renderApp = render | ||
const renderError = (error) => { | ||
const RedBox = require('redbox-react') | ||
ReactDOM.render( | ||
<RedBox error={error} />, | ||
rootEl | ||
) | ||
} | ||
render = () => { | ||
try { | ||
renderApp() | ||
} catch (error) { | ||
renderError(error) | ||
} | ||
} | ||
module.hot.accept('./containers/App', () => { | ||
setTimeout(render) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why do you need There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think the original motivation was to avoid errors thrown in There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Thanks for the information! I am working on my own hotloader for something, so I wonder how it is done in other implementations. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. hey, how are you able to use the old Following the HMR code for reducers in your other examples, wouldn't the callback of // render takes in a component to render
let render = (App) => ReactDOM.render(App, rootEl)
/* . . . */
module.hot.accept('./containers/App', () => {
const NextApp = require('./containers/App').default
render(NextApp)
}) There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Line 11 Even though the code inside |
||
}) | ||
} | ||
|
||
render() |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -15,7 +15,6 @@ module.exports = { | |
plugins: [ | ||
new webpack.optimize.OccurenceOrderPlugin(), | ||
new webpack.HotModuleReplacementPlugin(), | ||
new webpack.NoErrorsPlugin() | ||
], | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @gaearon Why did you remove NoErrorsPlugin? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. He's displaying them with react-redbox instead (see line 24). If he continued using the NoErrorsPlugin, Webpack would suppress the errors, and Redbox would just never be rendered anyway. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. No, this is not the reason. Redbox only catches runtime errors, it doesn’t help with syntax errors. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. That makes more sense, sorry for the incorrect explanation |
||
module: { | ||
loaders: [ | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why use ReactDOM.render() instead of plain render()?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
render is being assigned on line 10...