( elmOrDoc: Element | Document, defaultParentJSON?: Element )
| 146 | /** This pauses a running container in the browser. It is not used for SSR */ |
| 147 | // TODO(mhevery): this is a remnant when you could have paused on client. Should be deleted. |
| 148 | export const pauseContainer = async ( |
| 149 | elmOrDoc: Element | Document, |
| 150 | defaultParentJSON?: Element |
| 151 | ): Promise<SnapshotResult> => { |
| 152 | const doc = getDocument(elmOrDoc); |
| 153 | const documentElement = doc.documentElement; |
| 154 | const containerEl = isDocument(elmOrDoc) ? documentElement : elmOrDoc; |
| 155 | if (directGetAttribute(containerEl, QContainerAttr) === 'paused') { |
| 156 | throw qError(QError_containerAlreadyPaused); |
| 157 | } |
| 158 | const parentJSON = |
| 159 | defaultParentJSON ?? (containerEl === doc.documentElement ? doc.body : containerEl); |
| 160 | |
| 161 | const containerState = _getContainerState(containerEl); |
| 162 | const contexts = getNodesInScope(containerEl, hasContext); |
| 163 | |
| 164 | // Set container to paused |
| 165 | directSetAttribute(containerEl, QContainerAttr, 'paused'); |
| 166 | |
| 167 | // Update elements with context |
| 168 | for (const elCtx of contexts) { |
| 169 | const elm = elCtx.$element$; |
| 170 | const listeners = elCtx.li; |
| 171 | if (elCtx.$scopeIds$) { |
| 172 | const value = serializeSStyle(elCtx.$scopeIds$); |
| 173 | if (value) { |
| 174 | elm.setAttribute(QScopedStyle, value); |
| 175 | } |
| 176 | } |
| 177 | if (elCtx.$id$) { |
| 178 | elm.setAttribute(ELEMENT_ID, elCtx.$id$); |
| 179 | } |
| 180 | if (isElement(elm) && listeners.length > 0) { |
| 181 | const groups = groupListeners(listeners); |
| 182 | for (const listener of groups) { |
| 183 | elm.setAttribute(listener[0], serializeQRLs(listener[1], containerState, elCtx)); |
| 184 | } |
| 185 | } |
| 186 | } |
| 187 | |
| 188 | // Serialize data |
| 189 | const data = await _pauseFromContexts(contexts, containerState, (el) => { |
| 190 | if (isNode(el) && isText(el)) { |
| 191 | return getTextID(el, containerState); |
| 192 | } |
| 193 | return null; |
| 194 | }); |
| 195 | |
| 196 | // Emit Qwik JSON |
| 197 | const qwikJson = doc.createElement('script'); |
| 198 | directSetAttribute(qwikJson, 'type', 'qwik/json'); |
| 199 | qwikJson.textContent = escapeText(JSON.stringify(data.state, undefined, qDev ? ' ' : undefined)); |
| 200 | parentJSON.appendChild(qwikJson); |
| 201 | |
| 202 | // Emit event registration |
| 203 | const extraListeners = Array.from(containerState.$events$, (s) => JSON.stringify(s)); |
| 204 | const eventsScript = doc.createElement('script'); |
| 205 | eventsScript.textContent = `(window.qwikevents||=[]).push(${extraListeners.join(', ')})`; |
no test coverage detected
searching dependent graphs…