@@ -68,12 +68,19 @@ class ErrorBoundary extends React.Component {
68
68
}
69
69
70
70
export function Example() {
71
- const wrapped = < React.Profiler id = "Navigation" onRender = { console . log } > < ErrorBoundary > < App / > < /ErrorBoundary > < /React.Profiler >;
72
-
73
71
const clientAppEl = document . getElementById ( 'clientApp' ) ;
74
- clientAppEl . dispatchEvent ( new CustomEvent ( 'reset' ) ) ;
72
+
73
+ const wrapped = < React.Profiler id = "App" onRender ={ ( id , phase , actualDuration , baseDuration , startTime , commitTime , interactions ) => {
74
+ clientAppEl . dispatchEvent ( new CustomEvent ( 'DID_RENDER' , { detail: { id , phase , actualDuration , baseDuration , startTime , commitTime , interactions } } ) ) ;
75
+ } } >
76
+ < ErrorBoundary >
77
+ < App / >
78
+ < /ErrorBoundary >
79
+ < /React.Profiler >;
80
+
81
+ clientAppEl . dispatchEvent ( new CustomEvent ( 'RESET' ) ) ;
75
82
ReactDOM. render ( wrapped , clientAppEl ) ;
76
- clientAppEl . addEventListener ( 'reset ' , ( ) => {
83
+ clientAppEl. addEventListener ( 'RESET ' , ( ) => {
77
84
ReactDOM . unmountComponentAtNode ( clientAppEl ) ;
78
85
} , { once: true } ) ;
79
86
@@ -97,7 +104,7 @@ function useTick() {
97
104
function useDebouncer(duration) {
98
105
const [ count , tick ] = useTick ( ) ;
99
106
100
- const effect = useMemo ( ( ) => {
107
+ const callback = useMemo ( ( ) => {
101
108
let timeout = null ;
102
109
function clear ( ) {
103
110
if ( timeout ) {
@@ -112,7 +119,7 @@ function useDebouncer(duration) {
112
119
} ;
113
120
} , [ duration , tick ] ) ;
114
121
115
- return [ count , effect ] ;
122
+ return [ count , callback ] ;
116
123
}
117
124
118
125
export default function App() {
@@ -248,9 +255,8 @@ require(["vs/editor/editor.main"], function () {
248
255
return new Map()
249
256
.set('result', result)
250
257
.set('error', '')
251
- .set('esbuildMs', duration.toString() + 'ms')
252
- .set('esbuildBytes', (codeBytes / 1024).toFixed(2) + ' KB')
253
- .set('renderMs', '');
258
+ .set('esbuildMs', duration.toString() + 'ms to compile')
259
+ .set('esbuildBytes', (codeBytes / 1024).toFixed(2) + ' KB to download');
254
260
})
255
261
.catch((err) => {
256
262
return new Map().set('error', 'Error ' + err.message);
@@ -273,18 +279,28 @@ require(["vs/editor/editor.main"], function () {
273
279
input.onDidChangeModelContent(onEdit);
274
280
const model = input.getModel();
275
281
model.setValue(input.getValue() + " \n");
282
+
283
+ const clientAppEl = document.getElementById('clientApp');
284
+ let renderCount = 0;
285
+ clientAppEl.addEventListener('DID_RENDER', ({ detail }) => {
286
+ renderCount++;
287
+ console.log(" DID_RENDER ");
288
+ document.querySelector('#clientResult slot[name="reactRenderDuration "]').textContent = `last ${detail.actualDuration}ms; ${renderCount} times rendered`;
289
+ });
276
290
} );
277
291
</ script >
278
292
< output id = status class = "block text-xs opacity-50 " > </ output >
279
- < output id = result class = "block text-xs " >
280
- < div class = "text-red-500 " > < slot name = error > </ slot > </ div >
281
- < div > esbuild: < slot name = esbuildMs > </ slot > < slot name = esbuildBytes > </ slot > </ div >
282
- < div > < slot name = renderMs > </ slot > </ div >
283
- </ output >
293
+ < div class = "flex " >
294
+ < output id = result class = "block text-xs " >
295
+ < div class = "text-red-500 " > < slot name = error > </ slot > </ div >
296
+ < div > esbuild: < slot name = esbuildMs > </ slot > , < slot name = esbuildBytes > </ slot > </ div >
297
+ </ output >
298
+ < div id = "clientResult " class = "ml-auto text-xs " > < slot name = reactRenderDuration > </ slot > </ div >
299
+ </ div >
284
300
< div class = "flex-container " id = "container " style = "display: flex; min-height: 100vh; " >
285
301
< div id = "input " style = "flex: 1; " > </ div >
286
302
< div class = "flex-1 flex flex-col " >
287
- < div id = "clientApp " style = "flex: 1; " > </ div >
303
+ < div id = "clientApp " style = "flex: 1; " class = " bg-white text-black " > </ div >
288
304
< div id = "htmlOutput " style = "flex: 1; " > </ div >
289
305
</ div >
290
306
</ div >
0 commit comments