Skip to content

Commit

Permalink
Merge pull request #1316 from gaearon/12.11
Browse files Browse the repository at this point in the history
12.11
  • Loading branch information
theKashey committed Aug 10, 2019
2 parents 1ea511e + 2cb544d commit e4806ab
Show file tree
Hide file tree
Showing 8 changed files with 158 additions and 135 deletions.
7 changes: 4 additions & 3 deletions examples/styled-components/src/index.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
import 'react-lifecycles-compat';
import 'babel-polyfill';
import React from 'react';
import { render } from 'react-dom';
import App from './App';

const root = document.createElement('div');
document.body.appendChild(root);
//const root = ;
document.body.appendChild(document.createElement('div'));

render(<App />, root);
render(<App />, document.getElementsByTagName('div')[0]);
19 changes: 17 additions & 2 deletions examples/styled-components/webpack.config.babel.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,24 @@ module.exports = {
module: {
rules: [
{
exclude: /packages/, // should work without exclude
exclude: /node_modules/, // should work without exclude
test: /\.js$/,
use: ['react-hot-loader/webpack', 'babel-loader'],
use: ['babel-loader'],
},
{
include: /node_modules\/react-lifecycles-compat/, // should work without exclude
test: /\.js$/,
use: ['babel-loader'],
},
{
include: /node_modules\/react-dom/,
test: /\.jsx?$/,
use: {
loader: 'react-hot-loader/webpack',
options: {
noRegister: true,
},
},
},
],
},
Expand Down
5 changes: 5 additions & 0 deletions index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,11 @@ export interface Config {
*/
disableHotRendererWhenInjected: boolean;

/**
* Show "hot-loader/react-dom" warning
*/
showReactDomPatchNotification: boolean;

/**
* flag to completely disable RHL for SFC
*/
Expand Down
8 changes: 4 additions & 4 deletions src/babel.dev.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ const shouldIgnoreFile = file =>
!!file
.split('\\')
.join('/')
.match(/node_modules\/(react|react-hot-loader)([\/]|$)/);
.match(/node_modules\/(react|react-dom|react-hot-loader)([\/]|$)/);

/* eslint-enable */

Expand Down Expand Up @@ -40,14 +40,14 @@ function plugin(args, options = {}) {

const headerTemplate = template(
`(function () {
var enterModule = (typeof reactHotLoaderGlobal !== 'undefined' ? reactHotLoaderGlobal : require('react-hot-loader')).enterModule;
var enterModule = (typeof reactHotLoaderGlobal !== 'undefined' ? reactHotLoaderGlobal.enterModule : undefined);
enterModule && enterModule(module);
}())`,
templateOptions,
);
const footerTemplate = template(
`(function () {
var leaveModule = (typeof reactHotLoaderGlobal !== 'undefined' ? reactHotLoaderGlobal : require('react-hot-loader')).leaveModule;
var leaveModule = (typeof reactHotLoaderGlobal !== 'undefined' ? reactHotLoaderGlobal.leaveModule : undefined);
leaveModule && leaveModule(module);
}())`,
templateOptions,
Expand All @@ -61,7 +61,7 @@ function plugin(args, options = {}) {
`
(function () {
var reactHotLoader = (typeof reactHotLoaderGlobal !== 'undefined' ? reactHotLoaderGlobal : require('react-hot-loader')).default;
var reactHotLoader = (typeof reactHotLoaderGlobal !== 'undefined' ? reactHotLoaderGlobal.default : undefined);
if (!reactHotLoader) {
return;
Expand Down
5 changes: 5 additions & 0 deletions src/reactHotLoader.js
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,11 @@ const reactHotLoader = {
patch(React, ReactDOM) {
let typeResolver = resolveType;
/* eslint-disable no-console */
if (ReactDOM && !ReactDOM.render) {
logger.error(
'React-Hot-Loader: broken state detected, please import React-Hot-Loader before react-dom, see https://github.com/gaearon/react-hot-loader/issues/1315',
);
}
if (ReactDOM && ReactDOM.setHotElementComparator) {
ReactDOM.setHotElementComparator(hotComponentCompare);
configuration.disableHotRenderer = configuration.disableHotRendererWhenInjected;
Expand Down
3 changes: 2 additions & 1 deletion src/webpack/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,8 @@ function transform(source, map) {
if (options.withPatch) {
source = patch(source);
}
if (source.indexOf('reactHotLoader.register') > 0) {

if (source.indexOf('reactHotLoader.register') > 0 || options.noRegister) {
return callback(null, source, map);
}
// This is a Webpack loader, but the user put it in the Babel config.
Expand Down
6 changes: 1 addition & 5 deletions src/webpack/webpackTagCommonJSExports.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,7 @@
void (function register() {
// eslint-disable-line no-extra-semi
/* react-hot-loader/webpack */
var safe_require = function() {
return typeof require === 'undefined' ? undefined : require('react-hot-loader');
};

var reactHotLoader = (typeof reactHotLoaderGlobal !== 'undefined' ? reactHotLoaderGlobal : safe_require()).default;
var reactHotLoader = typeof reactHotLoaderGlobal !== 'undefined' ? reactHotLoaderGlobal.default : undefined;

if (!reactHotLoader) {
return;
Expand Down
240 changes: 120 additions & 120 deletions test/__snapshots__/babel.test.js.snap

Large diffs are not rendered by default.

0 comments on commit e4806ab

Please sign in to comment.