( parent: Element | Document, jsxOutput: JSXOutput | FunctionComponent<any>, opts?: RenderOptions )
| 45 | * @public |
| 46 | */ |
| 47 | export const render = async ( |
| 48 | parent: Element | Document, |
| 49 | jsxOutput: JSXOutput | FunctionComponent<any>, |
| 50 | opts?: RenderOptions |
| 51 | ): Promise<RenderResult> => { |
| 52 | // If input is a component, convert it |
| 53 | if (typeof jsxOutput === 'function') { |
| 54 | jsxOutput = jsx(jsxOutput, null); |
| 55 | } |
| 56 | const doc = getDocument(parent); |
| 57 | const containerEl = getElement(parent); |
| 58 | if (qDev && containerEl.hasAttribute(QContainerAttr)) { |
| 59 | throw qError(QError_cannotRenderOverExistingContainer, containerEl); |
| 60 | } |
| 61 | // if (qDev) { |
| 62 | // if (parent.childNodes.length > 0) { |
| 63 | // throw new Error('Container must be empty before mounting anything inside'); |
| 64 | // } |
| 65 | // } |
| 66 | injectQContainer(containerEl); |
| 67 | |
| 68 | const containerState = _getContainerState(containerEl); |
| 69 | const serverData = opts?.serverData; |
| 70 | if (serverData) { |
| 71 | Object.assign(containerState.$serverData$, serverData); |
| 72 | } |
| 73 | const rCtx = createRenderContext(doc, containerState); |
| 74 | containerState.$hostsRendering$ = new Set(); |
| 75 | containerState.$styleMoved$ = true; |
| 76 | await renderRoot(rCtx, containerEl, jsxOutput, doc, containerState, containerEl); |
| 77 | |
| 78 | await postRendering(containerState, rCtx); |
| 79 | |
| 80 | return { |
| 81 | cleanup() { |
| 82 | cleanupContainer(rCtx, containerEl); |
| 83 | }, |
| 84 | }; |
| 85 | }; |
| 86 | |
| 87 | const renderRoot = async ( |
| 88 | rCtx: RenderContext, |
no test coverage detected
searching dependent graphs…