Skip to content

Commit f7a9381

Browse files
committed
feat: add timing instrumentation to LoadingOverlay
Track key milestones in the WebIframe loading pipeline: - Runtime (web-core + web-elements) initialization - Template URL assignment and shadowRoot polling - First content render detection (via MutationObserver or fallback timeout) This diagnostic data helps identify whether the 5s fallback timeout is actually triggering, and if the observer is missing early DOM insertions.
1 parent a8da7ef commit f7a9381

3 files changed

Lines changed: 21 additions & 2 deletions

File tree

.context/notes.md

Whitespace-only changes.

.context/todos.md

Whitespace-only changes.

src/example-preview/components/web-iframe.tsx

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,11 @@ export const WebIframe = ({ show, src }: WebIframeProps) => {
9393

9494
// Load web-core + web-elements eagerly on mount
9595
useEffect(() => {
96-
ensureRuntime().then(() => setReady(true));
96+
const t = performance.now();
97+
ensureRuntime().then(() => {
98+
console.log('[WebIframe] runtime ready', `${(performance.now() - t).toFixed(0)}ms`);
99+
setReady(true);
100+
});
97101
}, []);
98102

99103
// Update lynx-view dimensions to match the container.
@@ -116,6 +120,10 @@ export const WebIframe = ({ show, src }: WebIframeProps) => {
116120
// Set URL only after runtime is ready AND element is mounted
117121
useEffect(() => {
118122
if (ready && show && src && lynxViewRef.current && containerRef.current) {
123+
const t0 = performance.now();
124+
const tag = `[WebIframe ${src.split('/').pop()}]`;
125+
console.log(tag, 'effect start', { ready, show, src });
126+
119127
updateDimensions();
120128

121129
// @ts-ignore
@@ -158,6 +166,7 @@ export const WebIframe = ({ show, src }: WebIframeProps) => {
158166
return template;
159167
};
160168

169+
console.log(tag, 'url set', `+${(performance.now() - t0).toFixed(0)}ms`);
161170
lynxViewRef.current.url = src;
162171

163172
// Workaround: web-core reads MouseEvent.x/.y (viewport-relative) for
@@ -188,8 +197,15 @@ export const WebIframe = ({ show, src }: WebIframeProps) => {
188197
// The shadow root is created asynchronously by web-core after url is
189198
// set, so we poll until it becomes available before attaching observers.
190199
const setupShadow = (shadow: ShadowRoot) => {
200+
console.log(tag, 'shadow found', `+${(performance.now() - t0).toFixed(0)}ms`, {
201+
childElementCount: shadow.childElementCount,
202+
});
203+
191204
mo = new MutationObserver(() => {
192205
if (shadow.childElementCount > 0) {
206+
console.log(tag, 'rendered (observer)', `+${(performance.now() - t0).toFixed(0)}ms`, {
207+
childElementCount: shadow.childElementCount,
208+
});
193209
setRendered(true);
194210
mo!.disconnect();
195211
}
@@ -213,7 +229,10 @@ export const WebIframe = ({ show, src }: WebIframeProps) => {
213229
pollShadow();
214230

215231
// Fallback: hide loading after timeout
216-
const timer = setTimeout(() => setRendered(true), 5000);
232+
const timer = setTimeout(() => {
233+
console.log(tag, 'rendered (timeout fallback)', `+${(performance.now() - t0).toFixed(0)}ms`);
234+
setRendered(true);
235+
}, 5000);
217236
return () => {
218237
disposed = true;
219238
clearTimeout(timer);

0 commit comments

Comments
 (0)