1 |
|
2 |
|
3 | const errorEventHandlers = require('./utils/errorEventHandlers');
|
4 | const formatWebpackErrors = require('./utils/formatWebpackErrors');
|
5 |
|
6 |
|
7 | let isHotReload = false;
|
8 | let hasRuntimeErrors = false;
|
9 |
|
10 |
|
11 |
|
12 |
|
13 |
|
14 |
|
15 |
|
16 | function tryDismissErrorOverlay() {
|
17 | __react_refresh_error_overlay__.clearCompileError();
|
18 | __react_refresh_error_overlay__.clearRuntimeErrors(!hasRuntimeErrors);
|
19 | hasRuntimeErrors = false;
|
20 | }
|
21 |
|
22 |
|
23 |
|
24 |
|
25 |
|
26 | function handleCompileSuccess() {
|
27 | isHotReload = true;
|
28 |
|
29 | if (isHotReload) {
|
30 | tryDismissErrorOverlay();
|
31 | }
|
32 | }
|
33 |
|
34 |
|
35 |
|
36 |
|
37 |
|
38 |
|
39 | function handleCompileErrors(errors) {
|
40 | isHotReload = true;
|
41 |
|
42 | const formattedErrors = formatWebpackErrors(errors);
|
43 |
|
44 |
|
45 | __react_refresh_error_overlay__.showCompileError(formattedErrors[0]);
|
46 | }
|
47 |
|
48 |
|
49 |
|
50 |
|
51 |
|
52 |
|
53 |
|
54 | function compileMessageHandler(message) {
|
55 | switch (message.type) {
|
56 | case 'ok':
|
57 | case 'still-ok':
|
58 | case 'warnings': {
|
59 |
|
60 | handleCompileSuccess();
|
61 | break;
|
62 | }
|
63 | case 'errors': {
|
64 | handleCompileErrors(message.data);
|
65 | break;
|
66 | }
|
67 | default: {
|
68 |
|
69 | }
|
70 | }
|
71 | }
|
72 |
|
73 |
|
74 | if (process.env.NODE_ENV !== 'production' && typeof window !== 'undefined') {
|
75 |
|
76 | __react_refresh_init_socket__(compileMessageHandler, __resourceQuery);
|
77 |
|
78 | errorEventHandlers.error(function handleError(error) {
|
79 | hasRuntimeErrors = true;
|
80 | __react_refresh_error_overlay__.handleRuntimeError(error);
|
81 | });
|
82 | errorEventHandlers.unhandledRejection(function handleUnhandledPromiseRejection(error) {
|
83 | hasRuntimeErrors = true;
|
84 | __react_refresh_error_overlay__.handleRuntimeError(error);
|
85 | });
|
86 | }
|