@@ -68,12 +68,19 @@ class ErrorBoundary extends React.Component {
6868}
6969
7070export function Example() {
71- const wrapped = < React.Profiler id = "Navigation" onRender = { console . log } > < ErrorBoundary > < App / > < /ErrorBoundary > < /React.Profiler >;
72-
7371 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' ) ) ;
7582 ReactDOM. render ( wrapped , clientAppEl ) ;
76- clientAppEl . addEventListener ( 'reset ' , ( ) => {
83+ clientAppEl. addEventListener ( 'RESET ' , ( ) => {
7784 ReactDOM . unmountComponentAtNode ( clientAppEl ) ;
7885 } , { once: true } ) ;
7986
@@ -97,7 +104,7 @@ function useTick() {
97104function useDebouncer(duration) {
98105 const [ count , tick ] = useTick ( ) ;
99106
100- const effect = useMemo ( ( ) => {
107+ const callback = useMemo ( ( ) => {
101108 let timeout = null ;
102109 function clear ( ) {
103110 if ( timeout ) {
@@ -112,7 +119,7 @@ function useDebouncer(duration) {
112119 } ;
113120 } , [ duration , tick ] ) ;
114121
115- return [ count , effect ] ;
122+ return [ count , callback ] ;
116123}
117124
118125export default function App() {
@@ -248,9 +255,8 @@ require(["vs/editor/editor.main"], function () {
248255 return new Map()
249256 .set('result', result)
250257 .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');
254260 })
255261 .catch((err) => {
256262 return new Map().set('error', 'Error ' + err.message);
@@ -273,18 +279,28 @@ require(["vs/editor/editor.main"], function () {
273279 input.onDidChangeModelContent(onEdit);
274280 const model = input.getModel();
275281 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+ });
276290} );
277291</ script >
278292< 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 >
284300< div class = "flex-container " id = "container " style = "display: flex; min-height: 100vh; " >
285301 < div id = "input " style = "flex: 1; " > </ div >
286302 < 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 >
288304 < div id = "htmlOutput " style = "flex: 1; " > </ div >
289305 </ div >
290306</ div >
0 commit comments