Files

Return to Package Diff Home.
Brought to you by Intrinsic.

Package Diff: react-hot-loader @ 4.8.4 .. 4.8.8

babel.js

@@ -1,4 +1,4 @@
-'use strict'
+'use strict';
if (process.env.NODE_ENV === 'production') {
module.exports = require('./dist/babel.production.min.js');

CHANGELOG.md

@@ -2,6 +2,53 @@
All notable changes to this project will be documented in this file. See [standard-version](https://github.com/conventional-changelog/standard-version) for commit guidelines.
+<a name="4.8.8"></a>
+## [4.8.8](https://github.com/gaearon/react-hot-loader/compare/v4.8.7...v4.8.8) (2019-05-23)
+
+
+### Bug Fixes
+
+* disable RHL when NODE_ENV == test, fixes [#1252](https://github.com/gaearon/react-hot-loader/issues/1252) ([6f56d87](https://github.com/gaearon/react-hot-loader/commit/6f56d87))
+
+
+
+<a name="4.8.7"></a>
+## [4.8.7](https://github.com/gaearon/react-hot-loader/compare/v4.8.6...v4.8.7) (2019-05-20)
+
+
+### Bug Fixes
+
+* remove checks. fixes [#1252](https://github.com/gaearon/react-hot-loader/issues/1252) ([2b2f733](https://github.com/gaearon/react-hot-loader/commit/2b2f733))
+
+
+
+<a name="4.8.6"></a>
+## [4.8.6](https://github.com/gaearon/react-hot-loader/compare/v4.8.5...v4.8.6) (2019-05-18)
+
+
+### Bug Fixes
+
+* No HMR missing error in SSR ([956e52b](https://github.com/gaearon/react-hot-loader/commit/956e52b))
+* trailing commas at entrypoints, fixes [#1226](https://github.com/gaearon/react-hot-loader/issues/1226) ([989eebf](https://github.com/gaearon/react-hot-loader/commit/989eebf))
+
+
+
+<a name="4.8.5"></a>
+## [4.8.5](https://github.com/gaearon/react-hot-loader/compare/v4.8.4...v4.8.5) (2019-05-16)
+
+
+### Bug Fixes
+
+* correct memo fiber updater, fixes [#1230](https://github.com/gaearon/react-hot-loader/issues/1230) ([a185494](https://github.com/gaearon/react-hot-loader/commit/a185494))
+* make API more error prone, fixes [#1228](https://github.com/gaearon/react-hot-loader/issues/1228) ([a6ba488](https://github.com/gaearon/react-hot-loader/commit/a6ba488))
+* move react-dom notification to AppContainer, fixes [#1227](https://github.com/gaearon/react-hot-loader/issues/1227) ([28bfdd4](https://github.com/gaearon/react-hot-loader/commit/28bfdd4))
+* update root endpoint, fixes [#1226](https://github.com/gaearon/react-hot-loader/issues/1226), [#1240](https://github.com/gaearon/react-hot-loader/issues/1240) ([608805a](https://github.com/gaearon/react-hot-loader/commit/608805a))
+* use simpler conditions for index.js, implements [#1244](https://github.com/gaearon/react-hot-loader/issues/1244) ([4811d57](https://github.com/gaearon/react-hot-loader/commit/4811d57))
+* webpack plugin fails on hot-loader/react-dom, fixes #[#1234](https://github.com/gaearon/react-hot-loader/issues/1234) ([826eee3](https://github.com/gaearon/react-hot-loader/commit/826eee3))
+* webpack-plugin - use RHL global variable, fixes [#1251](https://github.com/gaearon/react-hot-loader/issues/1251) ([f036d36](https://github.com/gaearon/react-hot-loader/commit/f036d36))
+
+
+
<a name="4.8.4"></a>
## [4.8.4](https://github.com/gaearon/react-hot-loader/compare/v4.8.3...v4.8.4) (2019-04-15)

dist/babel.development.js

@@ -8,9 +8,10 @@
var templateOptions = {
placeholderPattern: /^([A-Z0-9]+)([A-Z0-9_]+)$/
+};
- /* eslint-disable */
-};var shouldIgnoreFile = function shouldIgnoreFile(file) {
+/* eslint-disable */
+var shouldIgnoreFile = function shouldIgnoreFile(file) {
return !!file.split('\\').join('/').match(/node_modules\/(react|react-hot-loader)([\/]|$)/);
};
/* eslint-enable */

dist/react-hot-loader.development.js

@@ -174,6 +174,9 @@
// Disable "hot-replacement-render" when injection into react-dom is made
disableHotRendererWhenInjected: false,
+ // Controls `react-🔥-dom patch` notification
+ showReactDomPatchNotification: true,
+
// Hook on babel component register.
onComponentRegister: false,
@@ -1295,8 +1298,7 @@
React__default.createElement(
'h2',
{ style: { margin: 0 } },
- '\u269B\uFE0F\uD83D\uDD25\uD83D\uDE2D: hot update was not successful',
- ' ',
+ '\u269B\uFE0F\uD83D\uDD25\uD83D\uDE2D: hot update was not successful ',
React__default.createElement(
'button',
{ onClick: this.toggle },
@@ -1483,6 +1485,8 @@
cacheBusterProp: true
}, fiber.memoizedProps);
}
+
+ if (fiber.stateNode) ;
};
var cleanupReact = function cleanupReact() {
@@ -2022,7 +2026,11 @@
generation = _ref.generation;
if (error && generation === get$1()) {
- return React__default.createElement(configuration.errorReporter || EmptyErrorPlaceholder, { error: error, errorInfo: errorInfo, component: this });
+ return React__default.createElement(configuration.errorReporter || EmptyErrorPlaceholder, {
+ error: error,
+ errorInfo: errorInfo,
+ component: this
+ });
}
if (this.hotComponentUpdate) {
@@ -2107,33 +2115,35 @@
var AppContainer = function (_React$Component) {
inherits(AppContainer, _React$Component);
- function AppContainer() {
- var _temp, _this, _ret;
+ AppContainer.getDerivedStateFromProps = function getDerivedStateFromProps(nextProps, prevState) {
+ if (prevState.generation !== get$1()) {
+ // Hot reload is happening.
+ return {
+ error: null,
+ generation: get$1()
+ };
+ }
+ return null;
+ };
+ function AppContainer(props) {
classCallCheck(this, AppContainer);
- for (var _len = arguments.length, args = Array(_len), _key = 0; _key < _len; _key++) {
- args[_key] = arguments[_key];
+ var _this = possibleConstructorReturn(this, _React$Component.call(this, props));
+
+ if (configuration.showReactDomPatchNotification) {
+ configuration.showReactDomPatchNotification = false;
+ console.warn('React-Hot-Loader: react-🔥-dom patch is not detected. React 16.6+ features may not work.');
}
- return _ret = (_temp = (_this = possibleConstructorReturn(this, _React$Component.call.apply(_React$Component, [this].concat(args))), _this), _this.state = {
+ _this.state = {
error: null,
errorInfo: null,
// eslint-disable-next-line react/no-unused-state
generation: 0
- }, _temp), possibleConstructorReturn(_this, _ret);
- }
-
- AppContainer.getDerivedStateFromProps = function getDerivedStateFromProps(nextProps, prevState) {
- if (prevState.generation !== get$1()) {
- // Hot reload is happening.
- return {
- error: null,
- generation: get$1()
};
+ return _this;
}
- return null;
- };
AppContainer.prototype.shouldComponentUpdate = function shouldComponentUpdate(prevProps, prevState) {
// Don't update the component if the state had an error and still has one.
@@ -2218,9 +2228,10 @@
AppContainer.defaultProps = {
errorBoundary: true
+};
- // trying first react-lifecycles-compat.polyfill, then trying react-lifecycles-compat, which could be .default
-};var realPolyfill = defaultPolyfill.polyfill || defaultPolyfill__default;
+// trying first react-lifecycles-compat.polyfill, then trying react-lifecycles-compat, which could be .default
+var realPolyfill = defaultPolyfill.polyfill || defaultPolyfill__default;
realPolyfill(AppContainer);
var lazyConstructor = '_ctor';
@@ -2310,7 +2321,7 @@
if (oldType.type === newType.type || areSwappable(oldType.type, newType.type)) {
if (baseType) {
// memo form different fibers, why?
- if (oldType === baseType) {
+ if (baseType.$$typeof === newType.$$typeof) {
setNewType(newType);
} else {
setNewType(newType.type);
@@ -2407,7 +2418,8 @@
increment();
}
if (isContextType({ type: type })) {
-['Provider', 'Consumer'].forEach(function (prop) {
+ // possible options - Context, Consumer, Provider.
+ ['Provider', 'Consumer'].forEach(function (prop) {
var descriptor = Object.getOwnPropertyDescriptor(type, prop);
if (descriptor && descriptor.value) {
updateFunctionProxyById(id + ':' + prop, descriptor.value, updateContext);
@@ -2448,9 +2460,8 @@
configuration.ignoreSFC = configuration.ignoreSFCWhenInjected;
reactHotLoader.IS_REACT_MERGE_ENABLED = true;
- } else {
- // Actually everything works...
- console.warn('React-Hot-Loader: react-🔥-dom patch is not detected. React 16.6+ features may not work.');
+ configuration.showReactDomPatchNotification = false;
+ // console.warn('react-🔥-loader activated.');
}
/* eslint-enable */
if (!React$$1.createElement.isPatchedByReactHotLoader) {
@@ -2578,19 +2589,19 @@
return TargetComponent;
};
-var makeHotExport = function makeHotExport(sourceModule) {
+var makeHotExport = function makeHotExport(sourceModule, moduleId) {
var updateInstances = function updateInstances(possibleError) {
if (possibleError && possibleError instanceof Error) {
console.error(possibleError);
return;
}
- var module = hotModule(sourceModule.id);
+ var module = hotModule(moduleId);
clearTimeout(module.updateTimeout);
module.updateTimeout = setTimeout(function () {
try {
- requireIndirect(sourceModule.id);
+ requireIndirect(moduleId);
} catch (e) {
- console.error('React-Hot-Loader: error detected while loading', sourceModule.id);
+ console.error('React-Hot-Loader: error detected while loading', moduleId);
console.error(e);
}
module.instances.forEach(function (inst) {
@@ -2615,20 +2626,26 @@
});
}
}
+ } else {
+ logger.warn('React-hot-loader: Hot Module Replacement is not enabled');
}
};
var hot = function hot(sourceModule) {
- if (!sourceModule || !sourceModule.id) {
+ if (!sourceModule) {
// this is fatal
- throw new Error('React-hot-loader: `hot` could not find the `id` property in the `module` you have provided');
+ throw new Error('React-hot-loader: `hot` was called without any argument provided');
+ }
+ var moduleId = sourceModule.id || sourceModule.i || sourceModule.filename;
+ if (!moduleId) {
+ console.error('`module` prodived', sourceModule);
+ throw new Error('React-hot-loader: `hot` could not find the `name` of the the `module` you have provided');
}
- var moduleId = sourceModule.id;
var module = hotModule(moduleId);
- makeHotExport(sourceModule);
+ makeHotExport(sourceModule, moduleId);
clearExceptions();
- var failbackTimer = chargeFailbackTimer(sourceModule.id);
+ var failbackTimer = chargeFailbackTimer(moduleId);
var firstHotRegistered = false;
// TODO: Ensure that all exports from this file are react components.

dist/webpack.development.js

@@ -77,7 +77,7 @@
}
if (source.indexOf(sign) >= 0) {
// already patched
- return;
+ return source;
}
for (var key in injectionStart) {
if (source.indexOf(injectionStart[key][0]) > 0 && source.indexOf(injectionEnd[key][0]) > 0) {

dist/webpack.production.min.js

@@ -1 +1 @@
-"use strict";function _interopDefault(e){return e&&"object"==typeof e&&"default"in e?e.default:e}Object.defineProperty(exports,"__esModule",{value:!0});var sourceMap=_interopDefault(require("source-map")),fs=_interopDefault(require("fs")),path=_interopDefault(require("path")),loaderUtils=_interopDefault(require("loader-utils")),SourceMapGenerator=sourceMap.SourceMapGenerator;function makeIdentitySourceMap(e,t){var n=new SourceMapGenerator;return n.setSourceContent(t,e),e.split("\n").forEach(function(e,r){n.addMapping({source:t,original:{line:r+1,column:0},generated:{line:r+1,column:0}})}),n.toJSON()}var makeIdentitySourceMap_1=makeIdentitySourceMap,injectionStart={16.6:["if (child.tag === Fragment ? element.type === REACT_FRAGMENT_TYPE : child.elementType === element.type)","if (child.tag === Fragment ? element.type === REACT_FRAGMENT_TYPE : hotCompareElements(child.elementType, element.type, hotUpdateChild(child), child.type))"],"16.6-compact":["if(child.tag===Fragment?element.type===REACT_FRAGMENT_TYPE:child.elementType===element.type)","if(child.tag===Fragment?element.type===REACT_FRAGMENT_TYPE:hotCompareElements(child.elementType,element.type, hotUpdateChild(child), child.type))"],16.4:["if (child.tag === Fragment ? element.type === REACT_FRAGMENT_TYPE : child.type === element.type) {","if (child.tag === Fragment ? element.type === REACT_FRAGMENT_TYPE : hotCompareElements(child.type, element.type, hotUpdateChild(child), child.type)) {"],"16.4-compact":["if(child.tag===Fragment?element.type===REACT_FRAGMENT_TYPE:child.type===element.type)","if(child.tag===Fragment?element.type===REACT_FRAGMENT_TYPE:hotCompareElements(child.type,element.type, hotUpdateChild(child), child.type))"]},additional={"16.6-update":["if (current$$1 !== null && current$$1.elementType === element.type) {","if (current$$1 !== null && hotCompareElements(current$$1.elementType, element.type, hotUpdateChild(current$$1),current$$1.type)) {"],"16.6-update-compact":["if(current$$1!==null&&current$$1.elementType===element.type)","if(current$$1!==null&&hotCompareElements(current$$1.elementType,element.type,hotUpdateChild(current$$1),current$$1.type))"],"16.4-update":["if (current !== null && current.type === element.type) {","if (current !== null && hotCompareElements(current.type, element.type, hotUpdateChild(current),current.type)) {"],"16.4-update-compact":["if (current!== null&&current.type===element.type)","if (current!== null&&hotCompareElements(current.type,element.type,hotUpdateChild(current)))"]},ReactHotLoaderInjection="\nvar hotUpdateChild = function (child) {\n return function (newType) {\n child.type = newType;\n if (child.alternate) {\n child.alternate.type = newType;\n }\n }\n};\nvar hotCompareElements = function (oldType, newType) {\n return oldType === newType\n};\nvar hotCleanupHooks = function () {\n if (typeof resetHooks !== 'undefined') {\n resetHooks();\n }\n}\nvar ReactDOM = {\n evalInReactContext: function (injection) {\n return eval(injection);\n },\n hotCleanup: hotCleanupHooks,\n hotRenderWithHooks: function (current, render) { \n hotCleanupHooks();\n \n if (typeof nextCurrentHook !== 'undefined' && typeof ReactCurrentDispatcher$1 !== 'undefined') { \n nextCurrentHook = current !== null ? current.memoizedState : null;\n if(typeof firstCurrentHook !== 'undefined') {\n firstCurrentHook = nextCurrentHook;\n }\n \n ReactCurrentDispatcher$1.current = nextCurrentHook === null ? HooksDispatcherOnMountInDEV : HooksDispatcherOnUpdateInDEV;\n }\n \n var rendered = render();\n \n hotCleanupHooks();\n \n return rendered;\n },\n setHotElementComparator: function (newComparator) {\n hotCompareElements = newComparator\n },\n",defaultEnd=["var ReactDOM = {",ReactHotLoaderInjection],defaultEndCompact=["var ReactDOM={",ReactHotLoaderInjection],injectionEnd={16.6:defaultEnd,16.4:defaultEnd,"16.6-compact":defaultEndCompact,"16.4-compact":defaultEndCompact},sign="/* 🔥 this is hot-loader/react-dom 🔥 */";function additionalTransform(e){for(var t in additional)e=e.split(additional[t][0]).join(additional[t][1]);return e}function transform(e){if(e.indexOf("reconcileSingleElement")<0)return e;if(!(e.indexOf(sign)>=0)){for(var t in injectionStart)if(e.indexOf(injectionStart[t][0])>0&&e.indexOf(injectionEnd[t][0])>0){var n=additionalTransform(e.replace(injectionStart[t][0],injectionStart[t][1]).replace(injectionEnd[t][0],injectionEnd[t][1]));return sign+"\n"+n+"\n"+sign}return e}}var patch=transform,SourceNode=sourceMap.SourceNode,SourceMapConsumer=sourceMap.SourceMapConsumer,tagCommonJSExportsSource=null;function transform$1(e,t){var n=this.async();return n(null,e,t)}transform$1.patch=patch;var webpack=transform$1;exports.default=webpack;
+"use strict";function _interopDefault(e){return e&&"object"==typeof e&&"default"in e?e.default:e}Object.defineProperty(exports,"__esModule",{value:!0});var sourceMap=_interopDefault(require("source-map")),fs=_interopDefault(require("fs")),path=_interopDefault(require("path")),loaderUtils=_interopDefault(require("loader-utils")),SourceMapGenerator=sourceMap.SourceMapGenerator;function makeIdentitySourceMap(e,t){var n=new SourceMapGenerator;return n.setSourceContent(t,e),e.split("\n").forEach(function(e,r){n.addMapping({source:t,original:{line:r+1,column:0},generated:{line:r+1,column:0}})}),n.toJSON()}var makeIdentitySourceMap_1=makeIdentitySourceMap,injectionStart={16.6:["if (child.tag === Fragment ? element.type === REACT_FRAGMENT_TYPE : child.elementType === element.type)","if (child.tag === Fragment ? element.type === REACT_FRAGMENT_TYPE : hotCompareElements(child.elementType, element.type, hotUpdateChild(child), child.type))"],"16.6-compact":["if(child.tag===Fragment?element.type===REACT_FRAGMENT_TYPE:child.elementType===element.type)","if(child.tag===Fragment?element.type===REACT_FRAGMENT_TYPE:hotCompareElements(child.elementType,element.type, hotUpdateChild(child), child.type))"],16.4:["if (child.tag === Fragment ? element.type === REACT_FRAGMENT_TYPE : child.type === element.type) {","if (child.tag === Fragment ? element.type === REACT_FRAGMENT_TYPE : hotCompareElements(child.type, element.type, hotUpdateChild(child), child.type)) {"],"16.4-compact":["if(child.tag===Fragment?element.type===REACT_FRAGMENT_TYPE:child.type===element.type)","if(child.tag===Fragment?element.type===REACT_FRAGMENT_TYPE:hotCompareElements(child.type,element.type, hotUpdateChild(child), child.type))"]},additional={"16.6-update":["if (current$$1 !== null && current$$1.elementType === element.type) {","if (current$$1 !== null && hotCompareElements(current$$1.elementType, element.type, hotUpdateChild(current$$1),current$$1.type)) {"],"16.6-update-compact":["if(current$$1!==null&&current$$1.elementType===element.type)","if(current$$1!==null&&hotCompareElements(current$$1.elementType,element.type,hotUpdateChild(current$$1),current$$1.type))"],"16.4-update":["if (current !== null && current.type === element.type) {","if (current !== null && hotCompareElements(current.type, element.type, hotUpdateChild(current),current.type)) {"],"16.4-update-compact":["if (current!== null&&current.type===element.type)","if (current!== null&&hotCompareElements(current.type,element.type,hotUpdateChild(current)))"]},ReactHotLoaderInjection="\nvar hotUpdateChild = function (child) {\n return function (newType) {\n child.type = newType;\n if (child.alternate) {\n child.alternate.type = newType;\n }\n }\n};\nvar hotCompareElements = function (oldType, newType) {\n return oldType === newType\n};\nvar hotCleanupHooks = function () {\n if (typeof resetHooks !== 'undefined') {\n resetHooks();\n }\n}\nvar ReactDOM = {\n evalInReactContext: function (injection) {\n return eval(injection);\n },\n hotCleanup: hotCleanupHooks,\n hotRenderWithHooks: function (current, render) { \n hotCleanupHooks();\n \n if (typeof nextCurrentHook !== 'undefined' && typeof ReactCurrentDispatcher$1 !== 'undefined') { \n nextCurrentHook = current !== null ? current.memoizedState : null;\n if(typeof firstCurrentHook !== 'undefined') {\n firstCurrentHook = nextCurrentHook;\n }\n \n ReactCurrentDispatcher$1.current = nextCurrentHook === null ? HooksDispatcherOnMountInDEV : HooksDispatcherOnUpdateInDEV;\n }\n \n var rendered = render();\n \n hotCleanupHooks();\n \n return rendered;\n },\n setHotElementComparator: function (newComparator) {\n hotCompareElements = newComparator\n },\n",defaultEnd=["var ReactDOM = {",ReactHotLoaderInjection],defaultEndCompact=["var ReactDOM={",ReactHotLoaderInjection],injectionEnd={16.6:defaultEnd,16.4:defaultEnd,"16.6-compact":defaultEndCompact,"16.4-compact":defaultEndCompact},sign="/* 🔥 this is hot-loader/react-dom 🔥 */";function additionalTransform(e){for(var t in additional)e=e.split(additional[t][0]).join(additional[t][1]);return e}function transform(e){if(e.indexOf("reconcileSingleElement")<0)return e;if(e.indexOf(sign)>=0)return e;for(var t in injectionStart)if(e.indexOf(injectionStart[t][0])>0&&e.indexOf(injectionEnd[t][0])>0){var n=additionalTransform(e.replace(injectionStart[t][0],injectionStart[t][1]).replace(injectionEnd[t][0],injectionEnd[t][1]));return sign+"\n"+n+"\n"+sign}return e}var patch=transform,SourceNode=sourceMap.SourceNode,SourceMapConsumer=sourceMap.SourceMapConsumer,tagCommonJSExportsSource=null;function transform$1(e,t){var n=this.async();return n(null,e,t)}transform$1.patch=patch;var webpack=transform$1;exports.default=webpack;

dist/webpackTagCommonJSExports.js

@@ -1,10 +1,16 @@
'use strict';
-/* eslint-disable global-require, import/no-unresolved */
+/* eslint-disable global-require, import/no-unresolved, no-var, camelcase, func-names */
+/* global __FILENAME__, reactHotLoaderGlobal */
+
(function register() {
// eslint-disable-line no-extra-semi
/* react-hot-loader/webpack */
- var reactHotLoader = require('react-hot-loader').default;
+ var safe_require = function safe_require() {
+ return typeof require === 'undefined' ? undefined : require('react-hot-loader');
+ };
+
+ var reactHotLoader = (typeof reactHotLoaderGlobal !== 'undefined' ? reactHotLoaderGlobal : safe_require()).default;
if (!reactHotLoader) {
return;
@@ -13,6 +19,9 @@
/* eslint-disable camelcase, no-undef */
var webpackExports = typeof __webpack_exports__ !== 'undefined' ? __webpack_exports__ : exports;
/* eslint-enable camelcase, no-undef */
+ if (!webpackExports) {
+ return;
+ }
if (typeof webpackExports === 'function') {
reactHotLoader.register(webpackExports, 'module.exports', __FILENAME__);

index.d.ts

@@ -1,21 +1,19 @@
-import * as React from 'react'
+import * as React from 'react';
interface ErrorReporterProps {
- error: any
+ error: any;
}
export interface AppContainerProps {
- errorBoundary?: boolean
- errorReporter?: React.ComponentType<ErrorReporterProps>
+ errorBoundary?: boolean;
+ errorReporter?: React.ComponentType<ErrorReporterProps>;
}
export interface AppChildren {
- children?: React.ReactElement<any>
+ children?: React.ReactElement<any>;
}
-export class AppContainer extends React.Component<
- AppContainerProps & AppChildren
-> {}
+export class AppContainer extends React.Component<AppContainerProps & AppChildren> {}
/**
* Marks module and a returns a HOC to mark a Component inside it as hot-exported
@@ -25,9 +23,7 @@
* @example marks current module as hot, and export MyComponent as HotExportedMyComponent
* export default hot(module)(MyComponent)
*/
-export function hot(
- module: any,
-): <T = React.ComponentType<any>>(Component: T, props?: AppContainerProps) => T
+export function hot(module: any): <T = React.ComponentType<any>>(Component: T, props?: AppContainerProps) => T;
/**
* Marks component as `cold`, and making it invisible for React-Hot-Loader.
@@ -38,7 +34,7 @@
* @example marks some component as cold
* export default cold(MyComponent)
*/
-export function cold<T = React.ComponentType<any>>(component: T): T
+export function cold<T = React.ComponentType<any>>(component: T): T;
/**
* Tests are types of two components equal
@@ -49,14 +45,11 @@
* @example test that some rendered component(ReactElement), has the same type as BaseComponent
* areComponentEqual(RenderedComponent.type, BaseComponent)
*/
-export function areComponentsEqual<T>(
- typeA: React.ComponentType<T>,
- typeB: React.ComponentType<T>,
-): boolean
+export function areComponentsEqual<T>(typeA: React.ComponentType<T>, typeB: React.ComponentType<T>): boolean;
export interface HotError {
- error: Error
- errorInfo?: React.ErrorInfo
+ error: Error;
+ errorInfo?: React.ErrorInfo;
}
export interface Config {
@@ -64,7 +57,7 @@
* Specify loglLevel, default to 'error', set it to false to disable logs.
* Available levels: ['debug', 'log', 'warn', 'error']
*/
- logLevel: string
+ logLevel: string;
/**
*
@@ -73,67 +66,63 @@
* @param {string} fileName - origin file
* @return {any}
*/
- onComponentRegister: (
- type: any,
- uniqueLocalName: string,
- fileName: string,
- ) => any
+ onComponentRegister: (type: any, uniqueLocalName: string, fileName: string) => any;
/**
*
* @param type {any} type being rendered. The first argument of React.createElement
* @param displayName {string} type display name (if exists)
*/
- onComponentCreate: (type: any, displayName: string) => any
+ onComponentCreate: (type: any, displayName: string) => any;
/**
* Allows using SFC without changes. leading to some components not updated
*/
- pureSFC: boolean
+ pureSFC: boolean;
/**
* keep render method unpatched, moving sideEffect to componentDidUpdate
*/
- pureRender: boolean
+ pureRender: boolean;
/**
* Allows SFC to be used, enables "intermediate" components used by Relay, should be disabled for Preact
*/
- allowSFC: boolean
+ allowSFC: boolean;
/**
* Disable "hot-replacement-render"
*/
- disableHotRenderer: boolean
+ disableHotRenderer: boolean;
/**
* Disable "hot-replacement-render" when injection into react-dom are made
*/
- disableHotRendererWhenInjected: boolean
+ disableHotRendererWhenInjected: boolean;
/**
* flag to completely disable RHL for SFC
*/
- ignoreSFC: boolean
+ ignoreSFC: boolean;
/**
* flag to completely disable RHL for Components
*/
- ignoreComponents: boolean
+ ignoreComponents: boolean;
/**
* default value for AppContainer errorOverlay
*/
- errorReporter: React.ComponentType<HotError>
+ errorReporter: React.ComponentType<HotError>;
/**
* Global error overlay
*/
- ErrorOverlay: React.ComponentType<{ errors: Array<HotError> }>
+ ErrorOverlay: React.ComponentType<{ errors: Array<HotError> }>;
}
/**
* Confugures how React Hot Loader works
* @param {Config} config
*/
-export function setConfig(config: Partial<Config>): void
+export function setConfig(config: Partial<Config>): void;

index.js

@@ -1,8 +1,14 @@
-'use strict'
+'use strict';
-var hasWindow = typeof window !== 'undefined';
-
-if (!module.hot || process.env.NODE_ENV === 'production' || !hasWindow) {
+if (process.env.NODE_ENV === 'production') {
+ module.exports = require('./dist/react-hot-loader.production.min.js');
+} else if (process.env.NODE_ENV === 'test') {
+ module.exports = require('./dist/react-hot-loader.production.min.js');
+} else if (typeof window === 'undefined') {
+ // this is just server environment
+ module.exports = require('./dist/react-hot-loader.production.min.js');
+} else if (!module.hot) {
+ console.error('React-Hot-Loader: Hot Module Replacement is not enabled');
module.exports = require('./dist/react-hot-loader.production.min.js');
} else {
var evalAllowed = false;

package.json

@@ -1,6 +1,6 @@
{
"name": "react-hot-loader",
- "version": "4.8.4",
+ "version": "4.8.8",
"description": "Tweak React components in real time.",
"main": "index.js",
"types": "index.d.ts",
@@ -50,6 +50,7 @@
"reload"
],
"devDependencies": {
+ "@hot-loader/react-dom": "^16.8.6",
"@types/react": "^16.7.13",
"babel-cli": "^6.7.5",
"babel-core": "^6.26.3",

patch.js

@@ -1,4 +1,4 @@
-'use strict'
+'use strict';
if (!module.hot || process.env.NODE_ENV === 'production') {
module.exports = require('./dist/react-hot-loader.production.min.js');

README.md

@@ -26,15 +26,6 @@
> of a dev dependency as it automatically ensures it is not executed in
> production and the footprint is minimal.
-## 🔥 HOT-LABS 🔥
-
-Latest (4.5.0+) version of React-Hot-Loader could be quite 🔥!
-
-> RHL will patch React, replace React-DOM by React-🔥-DOM and work with fiber directly
-
-* (required) [use webpack plugin](https://github.com/gaearon/react-hot-loader#webpack-plugin) to let RHL patch React-DOM for you.
-* (alternative) [use react-🔥-dom](https://github.com/gaearon/react-hot-loader#react--dom) to use already patched React-DOM.
-
## Getting started
1. Add `react-hot-loader/babel` to your `.babelrc`:
@@ -50,19 +41,46 @@
```js
// App.js
-import { hot } from 'react-hot-loader/root'
-const App = () => <div>Hello World!</div>
-export default hot(App)
+import { hot } from 'react-hot-loader/root';
+const App = () => <div>Hello World!</div>;
+export default hot(App);
```
-3. Make sure `react-hot-loader` is required before `react`.
+3. Make sure `react-hot-loader` is required before `react` and `react-dom`:
* or `import 'react-hot-loader'` in your main file (before React)
-* or have at least one variable in the same file (babel/webpack plugin would import react-hot-loader then)
-* or prepend your webpack entry point with `react-hot-loader/patch`, which will `import 'react-hot-loader'`, and nothing more.
+* or prepend your webpack entry point with `react-hot-loader/patch`
+
+4. If you need hooks support, use React-🔥-Dom
+
+## React-🔥-Dom
+
+React-🔥-Dom ([hot-loader/react-dom](https://github.com/hot-loader/react-dom)) replaces the "react-dom" package of the same version, but with additional patches to support hot reloading.
+
+There are 2 ways to install it:
+
+* Use **yarn** name resolution, so `@hot-loader/react-dom` would be installed instead of `react-dom`
-Keep in mind - the same rule is applied to `react-dom`, as long as it would (since 16.8.6) import `react` internally.
-React-hot-loader, to prevent dependency cycles(#1209), caused by the code it injects, **should be imported first**.
+```
+yarn add react-dom@npm:@hot-loader/react-dom
+```
+
+* Use webpack **aliases**
+
+```
+yarn add @hot-loader/react-dom
+```
+
+```js
+// webpack.conf
+...
+resolve: {
+ alias: {
+ 'react-dom': '@hot-loader/react-dom'
+ }
+}
+...
+```
### Old API
@@ -75,9 +93,9 @@
It is almost the same, but you have to pass `module` inside `hot`.
```js
-import { hot } from 'react-hot-loader'
-const App = () => <div>Hello World!</div>
-export default hot(module)(App)
+import { hot } from 'react-hot-loader';
+const App = () => <div>Hello World!</div>;
+export default hot(module)(App);
```
3. [Run webpack with Hot Module Replacement](https://webpack.js.org/guides/hot-module-replacement/#enabling-hmr):
@@ -124,12 +142,12 @@
```js
// ./containers/App.js
-import React from 'react'
-import { hot } from 'react-hot-loader'
+import React from 'react';
+import { hot } from 'react-hot-loader';
-const App = () => <div>Hello World!</div>
+const App = () => <div>Hello World!</div>;
-export default hot(module)(App)
+export default hot(module)(App);
```
### Migrating from [create-react-app](https://github.com/facebookincubator/create-react-app) without ejecting
@@ -212,6 +230,41 @@
Hot reloading code is just one line in the beginning and one line at the end of
each module so you might not need source maps at all.
+### Linking
+
+If you are using `npm link` or `yarn link` for development purposes, there is a chance you will get error `Module not found: Error: Cannot resolve module 'react-hot-loader'` or the linked package is not hot reloaded.
+
+There are 2 ways to fix `Module not found`:
+
+* Use [`include` in loader configuration](https://github.com/gaearon/react-hot-boilerplate/blob/master/webpack.config.js#L22) to only opt-in your app's files to processing.
+* Alternatively if you are using webpack, override the module resolution in your config:
+
+```js
+{
+ resolve: {
+ alias: {
+ 'react-hot-loader': path.resolve(path.join(__dirname, './node_modules/react-hot-loader')),
+ }
+ }
+}
+```
+
+And to make your linked package to be hot reloaded, it will need to use the patched version of `react` and `react-dom`, if you're using webpack, add this options to the alias config
+
+```js
+{
+ resolve: {
+ alias: {
+ 'react-hot-loader': path.resolve(path.join(__dirname, './node_modules/react-hot-loader')),
+ // add these 2 lines below so linked package will reference the patched version of `react` and `react-dom`
+ 'react': path.resolve(path.join(__dirname, './node_modules/react')),
+ 'react-dom': path.resolve(path.join(__dirname, './node_modules/react-dom')),
+ // or point react-dom above to './node_modules/@hot-loader/react-dom' if you are using React-🔥-Dom
+ }
+ }
+}
+```
+
## Preact
React-hot-loader should work out of the box with `preact-compat`, but, in case of pure preact, you will need
@@ -220,10 +273,10 @@
* create configuration file (setupHotLoader.js)
```js
-import reactHotLoader from 'react-hot-loader'
-import preact from 'preact'
+import reactHotLoader from 'react-hot-loader';
+import preact from 'preact';
-reactHotLoader.preact(preact)
+reactHotLoader.preact(preact);
```
* dont forget to import it
@@ -249,8 +302,8 @@
```js
class MyComponent extends React.Component {
- onClick = () => this.setState() // COULD NOT UPDATE
- variable = 1 // this is ok
+ onClick = () => this.setState(); // COULD NOT UPDATE
+ variable = 1; // this is ok
render() {} // this is ok
}
```
@@ -271,38 +324,11 @@
},
],
},
-}
+};
```
Webpack plugin will also land a "hot" patch to react-dom, making React-Hot-Loader more compliant to [the principles](https://github.com/gaearon/react-hot-loader/issues/1118).
-## React-🔥-Dom
-
-Another way to make RHL more compliant is to use _our_ version of React-Dom - [hot-loader/react-dom](https://github.com/hot-loader/react-dom)
-
-It is the same React-Dom, with the same version, just with our patches already landed inside.
-
-There is 2 ways to install it:
-
-* Use **yarn** name resolution, so `@hot-loader/react-dom` would be installed instead of `react-dom`
-
-```
-yarn add react-dom@npm:@hot-loader/react-dom
-```
-
-* Use webpack **aliases**
-
-```js
-// webpack.conf
-...
-resolve: {
- alias: {
- 'react-dom': '@hot-loader/react-dom'
- }
-}
-...
-```
-
### Code Splitting
If you want to use Code Splitting + React Hot Loader, the simplest solution is to pick one of our compatible library:
@@ -316,23 +342,23 @@
```js
// AsyncHello.js
-import { asyncComponent } from 'react-async-component'
+import { asyncComponent } from 'react-async-component';
// asyncComponent could not `hot-reload` itself.
const AsyncHello = asyncComponent({
resolve: () => import('./Hello'),
-})
+});
-export default AsyncHello
+export default AsyncHello;
```
```js
// Hello.js
-import { hot } from 'react-hot-loader'
+import { hot } from 'react-hot-loader';
-const Hello = () => 'Hello'
+const Hello = () => 'Hello';
-export default hot(module)(Hello) // <-- module will reload itself
+export default hot(module)(Hello); // <-- module will reload itself
```
### Checking Element `type`s
@@ -341,28 +367,28 @@
reference types of elements won't work:
```js
-const element = <Component />
-console.log(element.type === Component) // false
+const element = <Component />;
+console.log(element.type === Component); // false
```
React Hot Loader exposes a function `areComponentsEqual` to make it possible:
```js
-import { areComponentsEqual } from 'react-hot-loader'
-const element = <Component />
-areComponentsEqual(element.type, Component) // true
+import { areComponentsEqual } from 'react-hot-loader';
+const element = <Component />;
+areComponentsEqual(element.type, Component); // true
```
Another way - compare "rendered" element type
```js
-const element = <Component />
-console.log(element.type === <Component />.type) // true
+const element = <Component />;
+console.log(element.type === <Component />.type); // true
// better - precache rendered type
-const element = <Component />
-const ComponentType = <Component />.type
-console.log(element.type === ComponentType) // true
+const element = <Component />;
+const ComponentType = <Component />.type;
+console.log(element.type === ComponentType); // true
```
But you might have to provide all required props. See [original issue](https://github.com/gaearon/react-hot-loader/issues/304).
@@ -373,8 +399,8 @@
> Not all components has a name. **In production displayName could not exists.**
```js
-const element = <Component />
-console.log(element.displayName === 'Component') // true
+const element = <Component />;
+console.log(element.displayName === 'Component'); // true
```
This is something we did not solve yet. Cold API could help keep original types.
@@ -387,7 +413,7 @@
new ExtractTextPlugin({
filename: 'styles/[name].[contenthash].css',
disable: NODE_ENV !== 'production',
-})
+});
```
#### Disabling a type change (❄️)
@@ -414,15 +440,14 @@
are not welcomed, and modules are not expected to change.
```js
-import { setConfig, cold } from 'react-hot-loader'
+import { setConfig, cold } from 'react-hot-loader';
setConfig({
- onComponentRegister: (type, name, file) =>
- file.indexOf('node_modules') > 0 && cold(type),
+ onComponentRegister: (type, name, file) => file.indexOf('node_modules') > 0 && cold(type),
// some components are not visible as top level variables,
// thus its not known where they were created
onComponentCreate: (type, name) => name.indexOf('styled') > 0 && cold(type),
-})
+});
```
! To be able to "cold" components from 'node_modules' you have to apply babel to node_modules, while this
@@ -448,13 +473,11 @@
* _cold_ components using hooks.
```js
-import { setConfig, cold } from 'react-hot-loader'
+import { setConfig, cold } from 'react-hot-loader';
setConfig({
onComponentCreate: (type, name) =>
- (String(type).indexOf('useState') > 0 ||
- String(type).indexOf('useEffect') > 0) &&
- cold(type),
-})
+ (String(type).indexOf('useState') > 0 || String(type).indexOf('useEffect') > 0) && cold(type),
+});
```
## API
@@ -490,11 +513,11 @@
**!!** Use `hot` only for module `exports`, not for module `imports`. **!!**
```js
-import { hot } from 'react-hot-loader/root'
+import { hot } from 'react-hot-loader/root';
-const App = () => 'Hello World!'
+const App = () => 'Hello World!';
-export default hot(App)
+export default hot(App);
```
Keep in mind - by importing `react-hot-loader/root` you are setting up a boundary for update event propagation.
@@ -518,11 +541,11 @@
only the second `(App)`. The "new" hot is using old API.
```js
-import { hot } from 'react-hot-loader'
+import { hot } from 'react-hot-loader';
-const App = () => 'Hello World!'
+const App = () => 'Hello World!';
-export default hot(module)(App)
+export default hot(module)(App);
```
### `AppContainer`
@@ -532,10 +555,10 @@
This low-level approach lets you make **hot **imports\_\_, not exports.
```js
-import React from 'react'
-import ReactDOM from 'react-dom'
-import { AppContainer } from 'react-hot-loader'
-import App from './containers/App'
+import React from 'react';
+import ReactDOM from 'react-dom';
+import { AppContainer } from 'react-hot-loader';
+import App from './containers/App';
const render = Component => {
ReactDOM.render(
@@ -543,10 +566,10 @@
<Component />
</AppContainer>,
document.getElementById('root'),
- )
-}
+ );
+};
-render(App)
+render(App);
// webpack Hot Module Replacement API
if (module.hot) {
@@ -554,10 +577,10 @@
// while `hot` would configure HMR for the CURRENT module
module.hot.accept('./containers/App', () => {
// if you are using harmony modules ({modules:false})
- render(App)
+ render(App);
// in all other cases - re-require App manually
- render(require('./containers/App'))
- })
+ render(require('./containers/App'));
+ });
}
```
@@ -566,11 +589,11 @@
Test if two components have the same type.
```js
-import { areComponentsEqual } from 'react-hot-loader'
-import Component1 from './Component1'
-import Component2 from './Component2'
+import { areComponentsEqual } from 'react-hot-loader';
+import Component1 from './Component1';
+import Component2 from './Component2';
-areComponentsEqual(Component1, Component2) // true or false
+areComponentsEqual(Component1, Component2); // true or false
```
### setConfig(config)
@@ -588,9 +611,9 @@
```js
// rhlConfig.js
-import { setConfig } from 'react-hot-loader'
+import { setConfig } from 'react-hot-loader';
-setConfig({ logLevel: 'debug' })
+setConfig({ logLevel: 'debug' });
```
**It is important** to set configuration before any other action will take a place
@@ -614,19 +637,19 @@
```js
// App.js
-import React from 'react'
+import React from 'react';
-const App = () => <div>Hello world!</div>
+const App = () => <div>Hello world!</div>;
-export default App
+export default App;
```
```js
// main.js
-import React from 'react'
-import ReactDOM from 'react-dom'
-import { AppContainer } from 'react-hot-loader'
-import App from './containers/App'
+import React from 'react';
+import ReactDOM from 'react-dom';
+import { AppContainer } from 'react-hot-loader';
+import App from './containers/App';
const render = Component => {
ReactDOM.render(
@@ -634,19 +657,19 @@
<Component />
</AppContainer>,
document.getElementById('root'),
- )
-}
+ );
+};
-render(App)
+render(App);
// webpack Hot Module Replacement API
if (module.hot) {
module.hot.accept('./containers/App', () => {
// if you are using harmony modules ({modules:false})
- render(App)
+ render(App);
// in all other cases - re-require App manually
- render(require('./containers/App'))
- })
+ render(require('./containers/App'));
+ });
}
```
@@ -654,21 +677,21 @@
```js
// App.js
-import React from 'react'
-import { hot } from 'react-hot-loader'
+import React from 'react';
+import { hot } from 'react-hot-loader';
-const App = () => <div>Hello world!</div>
+const App = () => <div>Hello world!</div>;
-export default hot(module)(App)
+export default hot(module)(App);
```
```js
// main.js
-import React from 'react'
-import ReactDOM from 'react-dom'
-import App from './containers/App'
+import React from 'react';
+import ReactDOM from 'react-dom';
+import App from './containers/App';
-ReactDOM.render(<App />, document.getElementById('root'))
+ReactDOM.render(<App />, document.getElementById('root'));
```
### Patch is optional
@@ -692,11 +715,11 @@
However - this option affects only SFC behavior, and any ClassComponent would boundary itself.
```js
-import { setConfig } from 'react-hot-loader'
-import ErrorBoundary from './ErrorBoundary'
+import { setConfig } from 'react-hot-loader';
+import ErrorBoundary from './ErrorBoundary';
// ErrorBoundary will be given error and errorInfo prop.
-setConfig({ errorReporter: ErrorBoundary })
+setConfig({ errorReporter: ErrorBoundary });
```
If `errorReporter` is not set - full screen error overlay would be shown.
@@ -711,10 +734,10 @@
```js
// to disable
-setConfig({ ErrorOverlay: () => null })
+setConfig({ ErrorOverlay: () => null });
// to change
-setConfig({ ErrorOverlay: MyErrorOverlay })
+setConfig({ ErrorOverlay: MyErrorOverlay });
```
The UX of existing overlay is a subject to change, and we are open to any proposals.
@@ -759,8 +782,8 @@
not working properly in your application.
```js
-import { setConfig } from 'react-hot-loader'
-setConfig({ logLevel: 'debug' })
+import { setConfig } from 'react-hot-loader';
+setConfig({ logLevel: 'debug' });
```
## Contributors

root.d.ts

@@ -1,7 +1,4 @@
-import * as React from 'react'
-import { AppContainerProps } from './index'
+import * as React from 'react';
+import { AppContainerProps } from './index';
-export function hot<T = React.ComponentType<any>>(
- Component: T,
- props?: AppContainerProps,
-): T
+export function hot<T = React.ComponentType<any>>(Component: T, props?: AppContainerProps): T;

root.js

@@ -1,23 +1,28 @@
if (module.hot) {
- var hot = require('./index').hot
- var cache = require.cache
+ var hot = require('./index').hot;
+ var cache = require.cache;
- if (!module.parents || !module.parents[0]) {
+ if (!module.parents || module.parents.length === 0) {
throw new Error(
- 'React-Hot-Loader: `react-hot-loader/root` is not supported on your system. '+
+ 'React-Hot-Loader: `react-hot-loader/root` is not supported on your system. ' +
'Please use `import {hot} from "react-hot-loader"` instead'
- )
+ );
}
// access parent
- var parent = cache[module.parents[0]]
- // remove itself from a cache
- delete cache[module.id]
+ var parent = cache[module.parents[0]];
+ if (!parent) {
+ throw new Error(
+ 'React-Hot-Loader: `react-hot-loader/root` is not supported on your system. ' +
+ 'Please use `import {hot} from "react-hot-loader"` instead'
+ );
+ }
+ // remove self from a cache
+ delete cache[module.id];
// setup hot for caller
-
- exports.hot = hot(Object.assign({ id: parent.i }, parent))
+ exports.hot = hot(parent);
} else {
// prod mode
exports.hot = function(a) {
- return a
- }
+ return a;
+ };
}

webpack.js

@@ -1,5 +1,5 @@
if (process.env.NODE_ENV === 'production') {
- module.exports = require('./dist/webpack.production.min.js')
+ module.exports = require('./dist/webpack.production.min.js');
} else {
- module.exports = require('./dist/webpack.development.js')
+ module.exports = require('./dist/webpack.development.js');
}