Skip to content

Commit 4f079c6

Browse files
committed
feat: replace warnings by configure({ debug: true })
1 parent 4152093 commit 4f079c6

13 files changed

+22
-63
lines changed

Diff for: README.md

+10
Original file line numberDiff line numberDiff line change
@@ -275,6 +275,16 @@ We're also gathering
275275
**[Troubleshooting Recipes](https://github.com/gaearon/react-hot-loader/blob/next/docs/Troubleshooting.md)**
276276
so send a PR if you have a lesson to share!
277277

278+
### Activate debug mode
279+
280+
Debug mode adds additional warnings and can tells you why React Hot Loader is
281+
not working properly in your application.
282+
283+
```js
284+
import { configure } from 'react-hot-loader'
285+
configure({ debug: true })
286+
```
287+
278288
## License
279289

280290
MIT

Diff for: packages/react-hot-loader/README.md

-4
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,6 @@ npm install react-hot-loader
1212

1313
Mark a component as hot.
1414

15-
Available options are:
16-
17-
* `warnings`: Enable some warnings (default to `true`)
18-
1915
```js
2016
import { hot } from 'react-hot-loader'
2117

Diff for: packages/react-hot-loader/react-hot-loader.d.ts

-1
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@ declare module 'react-hot-loader' {
1010
errorReporter?:
1111
| React.ComponentClass<ErrorReporterProps>
1212
| React.StatelessComponent<ErrorReporterProps>
13-
warnings?: boolean
1413
}
1514

1615
export class AppContainer extends React.Component<

Diff for: packages/react-hot-loader/src/AppContainer.dev.js

-9
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,6 @@ class AppContainer extends React.Component {
99
constructor(props) {
1010
super(props)
1111

12-
if (typeof __REACT_HOT_LOADER__ !== 'undefined') {
13-
__REACT_HOT_LOADER__.warnings = props.warnings
14-
}
15-
1612
this.state = {
1713
error: null,
1814
generation: 0,
@@ -88,11 +84,6 @@ AppContainer.propTypes = {
8884
return undefined
8985
},
9086
errorReporter: PropTypes.oneOfType([PropTypes.node, PropTypes.func]),
91-
warnings: PropTypes.bool,
92-
}
93-
94-
AppContainer.defaultProps = {
95-
warnings: true,
9687
}
9788

9889
export default AppContainer

Diff for: packages/react-hot-loader/src/index.dev.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
export { default as AppContainer } from './AppContainer.dev'
2-
export { hot, areComponentsEqual } from './utils.dev'
2+
export * from './utils.dev'
33

44
export default function warnAboutIncorrectUsage(arg) {
55
if (this && this.callback) {

Diff for: packages/react-hot-loader/src/index.prod.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
11
export { default as AppContainer } from './AppContainer.prod'
2-
export { hot, areComponentsEqual } from './utils.prod'
2+
export * from './utils.prod'

Diff for: packages/react-hot-loader/src/patch.dev.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ const hooks = {
3030
resetProxies(useWeakMap)
3131
},
3232

33-
warnings: true,
33+
debug: false,
3434
disableComponentProxy: false,
3535
}
3636

Diff for: packages/react-hot-loader/src/reconciler/hotReplacementRender.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -199,7 +199,7 @@ const hotReplacementRender = (instance, stack) => {
199199
updateProxyById(stackChild.instance[PROXY_KEY], childType)
200200

201201
next(stackChild.instance)
202-
} else if (__REACT_HOT_LOADER__.warnings) {
202+
} else if (__REACT_HOT_LOADER__.debug) {
203203
console.warn(
204204
`React-hot-loader: a ${getDisplayName(
205205
childType,

Diff for: packages/react-hot-loader/src/utils.dev.js

+6-3
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ const makeHotExport = (sourceModule, getInstances) => {
3636
}
3737
}
3838

39-
const hot = sourceModule => {
39+
export const hot = sourceModule => {
4040
let instances = []
4141
makeHotExport(sourceModule, () => instances)
4242
// TODO: Ensure that all exports from this file are react components.
@@ -73,6 +73,9 @@ const hot = sourceModule => {
7373
}
7474
}
7575

76-
const areComponentsEqual = (a, b) => getProxyByType(a) === getProxyByType(b)
76+
export const areComponentsEqual = (a, b) =>
77+
getProxyByType(a) === getProxyByType(b)
7778

78-
export { hot, areComponentsEqual }
79+
export const configure = ({ debug }) => {
80+
__REACT_HOT_LOADER__.debug = debug
81+
}

Diff for: packages/react-hot-loader/src/utils.prod.js

+1
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,3 @@
11
export const areComponentsEqual = (a, b) => a === b
22
export const hot = () => Component => Component
3+
export const configure = () => {}

Diff for: packages/react-hot-loader/test/AppContainer.dev.test.js

-21
Original file line numberDiff line numberDiff line change
@@ -1393,27 +1393,6 @@ function runAllTests(useWeakMap) {
13931393
expect(wrapper.text()).toBe('new render + old state + 20')
13941394
})
13951395
})
1396-
1397-
describe('container props', () => {
1398-
it('can disable warnings', () => {
1399-
mount(
1400-
<AppContainer>
1401-
<div>hey</div>
1402-
</AppContainer>,
1403-
)
1404-
1405-
expect(RHL.warnings).toBe(true)
1406-
1407-
mount(
1408-
<AppContainer warnings={false}>
1409-
<div>hey</div>
1410-
</AppContainer>,
1411-
)
1412-
1413-
expect(RHL.warnings).toBe(false)
1414-
delete RHL.warnings
1415-
})
1416-
})
14171396
})
14181397
}
14191398

Diff for: packages/react-hot-loader/test/patch.dev.test.js

-20
Original file line numberDiff line numberDiff line change
@@ -145,26 +145,6 @@ function runAllTests(useWeakMap) {
145145
}
146146
})
147147

148-
it("doesn't report disabled warnings", () => {
149-
const f1 = () => <div>123</div>
150-
const dynamic = () => () => <div>123</div>
151-
const spy = jest.spyOn(console, 'warn').mockImplementation(() => {})
152-
153-
try {
154-
RHL.warnings = false
155-
156-
RHL.register(f1, 'f1', '/wow/test.js')
157-
React.createElement(dynamic())
158-
RHL.register(f1, 'f1', '/wow/test.js')
159-
React.createElement(dynamic())
160-
161-
expect(console.warn.mock.calls.length).toBe(0)
162-
} finally {
163-
spy.mockRestore()
164-
delete RHL.warnings
165-
}
166-
})
167-
168148
it('resolves registered types by their last ID', () => {
169149
RHL.register(A1, 'a', 'test.js')
170150
const A = <A1 />.type

Diff for: packages/react-hot-loader/test/reconciler.test.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ describe('reconciler', () => {
8484
)
8585

8686
const wrapper = mount(
87-
<AppContainer warnings={false}>
87+
<AppContainer>
8888
<App />
8989
</AppContainer>,
9090
)

0 commit comments

Comments
 (0)