Skip to content

Commit ec6c880

Browse files
feat: use enqueue function
1 parent 5a2ba49 commit ec6c880

File tree

2 files changed

+24
-27
lines changed

2 files changed

+24
-27
lines changed

packages/qwik/src/core/ssr/ssr-render-jsx.ts

Lines changed: 20 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,13 @@ import { Fragment, directGetPropsProxyProp } from '../shared/jsx/jsx-runtime';
55
import { Slot } from '../shared/jsx/slot.public';
66
import type { JSXNodeInternal, JSXOutput } from '../shared/jsx/types/jsx-node';
77
import type { JSXChildren } from '../shared/jsx/types/jsx-qwik-attributes';
8-
import { SSRComment, SSRRaw, SSRStream, type SSRStreamChildren } from '../shared/jsx/utils.public';
8+
import {
9+
SSRBackpatch,
10+
SSRComment,
11+
SSRRaw,
12+
SSRStream,
13+
type SSRStreamChildren,
14+
} from '../shared/jsx/utils.public';
915
import { createQRL, type QRLInternal } from '../shared/qrl/qrl-class';
1016
import type { QRL } from '../shared/qrl/qrl.public';
1117
import { qrlToString, type SerializationContext } from '../shared/shared-serialization';
@@ -245,13 +251,7 @@ function processJSXNode(
245251
ssr.closeFragment();
246252
}
247253
} else if (type === SSRComment) {
248-
const commentData = directGetPropsProxyProp(jsx, 'data') || '';
249-
const commentContent = String(commentData);
250-
if (commentContent.startsWith('qwik:backpatch')) {
251-
ssr.commentNode(handleBackpatchComment(ssr, commentContent));
252-
} else {
253-
ssr.commentNode(commentContent);
254-
}
254+
ssr.commentNode(directGetPropsProxyProp(jsx, 'data') || '');
255255
} else if (type === SSRStream) {
256256
ssr.commentNode(FLUSH_COMMENT);
257257
const generator = jsx.children as SSRStreamChildren;
@@ -274,6 +274,18 @@ function processJSXNode(
274274
isPromise(value) && enqueue(Promise);
275275
} else if (type === SSRRaw) {
276276
ssr.htmlNode(directGetPropsProxyProp(jsx, 'data'));
277+
} else if (type === SSRBackpatch) {
278+
const backpatchScopeId = getNextUniqueIndex(ssr);
279+
ssr.enterBackpatchScope?.(backpatchScopeId);
280+
281+
enqueue(() => {
282+
if (ssr.currentBackpatchScope === backpatchScopeId) {
283+
ssr.exitBackpatchScope?.(backpatchScopeId);
284+
}
285+
});
286+
287+
const children = jsx.children as JSXOutput;
288+
children != null && enqueue(children);
277289
} else if (isQwikComponent(type)) {
278290
// prod: use new instance of an array for props, we always modify props for a component
279291
ssr.openComponent(isDev ? [DEBUG_TYPE, VirtualType.Component] : []);
@@ -554,18 +566,3 @@ function appendClassIfScopedStyleExists(jsx: JSXNodeInternal, styleScoped: strin
554566
jsx.constProps['class'] = '';
555567
}
556568
}
557-
558-
function handleBackpatchComment(ssr: SSRContainer, commentContent: string): string {
559-
if (commentContent === 'qwik:backpatch:start') {
560-
const backpatchScopeId = getNextUniqueIndex(ssr);
561-
ssr.enterBackpatchScope?.(backpatchScopeId);
562-
return `${commentContent}:${backpatchScopeId}`;
563-
} else if (commentContent === 'qwik:backpatch:end') {
564-
const currentBackpatchScope = ssr.currentBackpatchScope;
565-
if (currentBackpatchScope) {
566-
ssr.exitBackpatchScope?.(currentBackpatchScope);
567-
}
568-
return commentContent;
569-
}
570-
return commentContent;
571-
}

packages/qwik/src/core/tests/backpatch.spec.tsx

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ import { SSRBackpatch } from '../shared/jsx/utils.public';
1414
const debug = false;
1515

1616
describe('SSR Backpatching (attributes only, wrapper-scoped)', () => {
17-
it('emits marker and JSON blob inside wrapper when signal-derived attribute changes', async () => {
17+
it('emits marker and JSON blob when signal-derived attribute changes', async () => {
1818
const Ctx = createContextId<{ descId: Signal<string> }>('bp-ctx-1');
1919

2020
const Child = component$(() => {
@@ -39,7 +39,8 @@ describe('SSR Backpatching (attributes only, wrapper-scoped)', () => {
3939
const { document } = await ssrRenderToDom(<Root />, { debug });
4040
const html = document.documentElement.outerHTML;
4141

42-
expect(html).toMatch(/<input[^>]*\sq:reactive-id="/);
42+
// Should have reactive-id marker and patch data
43+
expect(html).toMatch(/q:reactive-id="/);
4344
expect(html).toMatch(/data-qwik-backpatch="/);
4445
expect(html).toContain('"type":"attribute"');
4546
expect(html).toContain('"name":"aria-describedby"');
@@ -71,8 +72,7 @@ describe('SSR Backpatching (attributes only, wrapper-scoped)', () => {
7172
const { document } = await ssrRenderToDom(<Root />, { debug });
7273
const html = document.documentElement.outerHTML;
7374

74-
expect(html).toMatch(/<input[^>]*\sq:reactive-id="/);
75-
75+
expect(html).toMatch(/q:reactive-id="/);
7676
expect(html).not.toMatch(/data-qwik-backpatch=/);
7777
});
7878

0 commit comments

Comments
 (0)