@@ -18,12 +18,18 @@ import { applyStyles } from './utils/dom/css';
18
18
19
19
import type { ErrorRecord } from './listenToRuntimeErrors' ;
20
20
21
+ type RuntimeReportingOptions = { |
22
+ onError : ( ) => void ,
23
+ launchEditorEndpoint : string ,
24
+ | } ;
25
+
21
26
let iframe : null | HTMLIFrameElement = null ;
22
27
let isLoadingIframe : boolean = false ;
23
28
24
29
let renderedElement : null | React . Element < any > = null ;
25
30
let currentBuildError : null | string = null ;
26
31
let currentRuntimeErrorRecords : Array < ErrorRecord > = [ ] ;
32
+ let currentRuntimeErrorOptions : null | RuntimeReportingOptions = null ;
27
33
let stopListeningToRuntimeErrors : null | ( ( ) => void ) = null ;
28
34
29
35
export function reportBuildError ( error : string ) {
@@ -36,14 +42,15 @@ export function dismissBuildError() {
36
42
update ( ) ;
37
43
}
38
44
39
- export function startReportingRuntimeErrors ( onError ?: ( ) => void ) {
45
+ export function startReportingRuntimeErrors ( options : RuntimeReportingOptions ) {
40
46
if ( stopListeningToRuntimeErrors !== null ) {
41
- return ;
47
+ throw new Error ( 'Already listening' ) ;
42
48
}
49
+ currentRuntimeErrorOptions = options ;
43
50
listenToRuntimeErrors ( errorRecord => {
44
51
try {
45
- if ( typeof onError === 'function' ) {
46
- onError ( ) ;
52
+ if ( typeof options . onError === 'function' ) {
53
+ options . onError . call ( null ) ;
47
54
}
48
55
} finally {
49
56
handleRuntimeError ( errorRecord ) ;
@@ -62,12 +69,14 @@ function dismissRuntimeErrors() {
62
69
}
63
70
64
71
export function stopReportingRuntimeErrors ( ) {
65
- if ( stopListeningToRuntimeErrors !== null ) {
66
- try {
67
- stopListeningToRuntimeErrors ( ) ;
68
- } finally {
69
- stopListeningToRuntimeErrors = null ;
70
- }
72
+ if ( stopListeningToRuntimeErrors === null ) {
73
+ throw new Error ( 'Not currently listening' ) ;
74
+ }
75
+ currentRuntimeErrorOptions = null ;
76
+ try {
77
+ stopListeningToRuntimeErrors ( ) ;
78
+ } finally {
79
+ stopListeningToRuntimeErrors = null ;
71
80
}
72
81
}
73
82
@@ -114,10 +123,14 @@ function render() {
114
123
return < CompileErrorContainer error = { currentBuildError } /> ;
115
124
}
116
125
if ( currentRuntimeErrorRecords . length > 0 ) {
126
+ if ( ! currentRuntimeErrorOptions ) {
127
+ throw new Error ( 'Expected options to be injected.' ) ;
128
+ }
117
129
return (
118
130
< RuntimeErrorContainer
119
131
errorRecords = { currentRuntimeErrorRecords }
120
132
close = { dismissRuntimeErrors }
133
+ launchEditorEndpoint = { currentRuntimeErrorOptions . launchEditorEndpoint }
121
134
/>
122
135
) ;
123
136
}
0 commit comments