( rCtx: RenderContext, elCtx: QContext, attempt?: number )
| 26 | } |
| 27 | |
| 28 | export const executeComponent = ( |
| 29 | rCtx: RenderContext, |
| 30 | elCtx: QContext, |
| 31 | attempt?: number |
| 32 | ): ValueOrPromise<ExecuteComponentOutput> => { |
| 33 | elCtx.$flags$ &= ~HOST_FLAG_DIRTY; |
| 34 | elCtx.$flags$ |= HOST_FLAG_MOUNTED; |
| 35 | elCtx.$slots$ = []; |
| 36 | elCtx.li.length = 0; |
| 37 | |
| 38 | const hostElement = elCtx.$element$; |
| 39 | const componentQRL = elCtx.$componentQrl$; |
| 40 | const props = elCtx.$props$; |
| 41 | const iCtx = newInvokeContext(rCtx.$static$.$locale$, hostElement, undefined, RenderEvent); |
| 42 | const waitOn: Promise<unknown>[] = (iCtx.$waitOn$ = []); |
| 43 | assertDefined(componentQRL, `render: host element to render must have a $renderQrl$:`, elCtx); |
| 44 | assertDefined(props, `render: host element to render must have defined props`, elCtx); |
| 45 | |
| 46 | // Set component context |
| 47 | const newCtx = pushRenderContext(rCtx); |
| 48 | newCtx.$cmpCtx$ = elCtx; |
| 49 | newCtx.$slotCtx$ = undefined; |
| 50 | |
| 51 | // Invoke render hook |
| 52 | iCtx.$subscriber$ = [0, hostElement]; |
| 53 | iCtx.$renderCtx$ = rCtx; |
| 54 | |
| 55 | // Resolve render function |
| 56 | componentQRL.$setContainer$(rCtx.$static$.$containerState$.$containerEl$); |
| 57 | const componentFn = componentQRL.getFn(iCtx); |
| 58 | |
| 59 | return safeCall( |
| 60 | () => componentFn(props), |
| 61 | (jsxNode) => { |
| 62 | return maybeThen( |
| 63 | isServerPlatform() |
| 64 | ? maybeThen(promiseAllLazy(waitOn), () => |
| 65 | // Run dirty tasks before SSR output is generated. |
| 66 | maybeThen(executeSSRTasks(rCtx.$static$.$containerState$, rCtx), () => |
| 67 | promiseAllLazy(waitOn) |
| 68 | ) |
| 69 | ) |
| 70 | : promiseAllLazy(waitOn), |
| 71 | () => { |
| 72 | if (elCtx.$flags$ & HOST_FLAG_DIRTY) { |
| 73 | if (attempt && attempt > 100) { |
| 74 | logWarn(`Infinite loop detected. Element: ${elCtx.$componentQrl$?.$symbol$}`); |
| 75 | } else { |
| 76 | return executeComponent(rCtx, elCtx, attempt ? attempt + 1 : 1); |
| 77 | } |
| 78 | } |
| 79 | return { |
| 80 | node: jsxNode, |
| 81 | rCtx: newCtx, |
| 82 | }; |
| 83 | } |
| 84 | ); |
| 85 | }, |
no test coverage detected
searching dependent graphs…