MCPcopy
hub / github.com/QwikDev/qwik / pauseContainer

Function pauseContainer

packages/qwik/src/core/container/pause.ts:148–209  ·  view source on GitHub ↗
(
  elmOrDoc: Element | Document,
  defaultParentJSON?: Element
)

Source from the content-addressed store, hash-verified

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.
148export 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(', ')})`;

Callers 3

store.unit.tsxFile · 0.90
appendQwikDevToolsFunction · 0.90
render.unit.tsxFile · 0.90

Calls 15

getDocumentFunction · 0.90
isDocumentFunction · 0.90
directGetAttributeFunction · 0.90
qErrorFunction · 0.90
_getContainerStateFunction · 0.90
directSetAttributeFunction · 0.90
serializeSStyleFunction · 0.90
isElementFunction · 0.90
groupListenersFunction · 0.90
serializeQRLsFunction · 0.90
isNodeFunction · 0.90
isTextFunction · 0.90

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…