Skip to content

Commit 72ba9f9

Browse files
committed
dont use async for processJSXNode
1 parent aa45990 commit 72ba9f9

File tree

1 file changed

+21
-6
lines changed

1 file changed

+21
-6
lines changed

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

Lines changed: 21 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -47,9 +47,17 @@ class ParentComponentData {
4747
public $componentFrame$: ISsrComponentFrame | null
4848
) {}
4949
}
50+
class MaybeAsyncSignal {}
51+
5052
type StackFn = () => ValueOrPromise<void>;
5153
type StackValue = ValueOrPromise<
52-
JSXOutput | StackFn | Promise<JSXOutput> | typeof Promise | ParentComponentData | AsyncGenerator
54+
| JSXOutput
55+
| StackFn
56+
| Promise<JSXOutput>
57+
| typeof Promise
58+
| ParentComponentData
59+
| AsyncGenerator
60+
| typeof MaybeAsyncSignal
5361
>;
5462

5563
/** @internal */
@@ -70,6 +78,14 @@ export async function _walkJSX(
7078
options.currentStyleScoped = value.$scopedStyle$;
7179
options.parentComponentFrame = value.$componentFrame$;
7280
continue;
81+
} else if (value === MaybeAsyncSignal) {
82+
// It could be an async signal, but it is not resolved yet, we need to wait for it.
83+
// We could do that in the processJSXNode,
84+
// but it will mean that we need to await it there, and it will return a promise.
85+
// We probably want to avoid creating a promise for all jsx nodes.
86+
const trackFn = stack.pop() as () => StackValue;
87+
await retryOnPromise(() => stack.push(trackFn()));
88+
continue;
7389
} else if (typeof value === 'function') {
7490
if (value === Promise) {
7591
stack.push(await (stack.pop() as Promise<JSXOutput>));
@@ -78,7 +94,7 @@ export async function _walkJSX(
7894
await (value as StackFn).apply(ssr);
7995
continue;
8096
}
81-
await processJSXNode(ssr, enqueue, value as JSXOutput, {
97+
processJSXNode(ssr, enqueue, value as JSXOutput, {
8298
styleScoped: options.currentStyleScoped,
8399
parentComponentFrame: options.parentComponentFrame,
84100
});
@@ -87,7 +103,7 @@ export async function _walkJSX(
87103
await drain();
88104
}
89105

90-
async function processJSXNode(
106+
function processJSXNode(
91107
ssr: SSRContainer,
92108
enqueue: (value: StackValue) => void,
93109
value: JSXOutput,
@@ -114,9 +130,8 @@ async function processJSXNode(
114130
ssr.openFragment(isDev ? [DEBUG_TYPE, VirtualType.WrappedSignal] : EMPTY_ARRAY);
115131
const signalNode = ssr.getLastNode();
116132
enqueue(ssr.closeFragment);
117-
await retryOnPromise(() => {
118-
enqueue(trackSignalAndAssignHost(value, signalNode, EffectProperty.VNODE, ssr));
119-
});
133+
enqueue(() => trackSignalAndAssignHost(value, signalNode, EffectProperty.VNODE, ssr));
134+
enqueue(MaybeAsyncSignal);
120135
} else if (isPromise(value)) {
121136
ssr.openFragment(isDev ? [DEBUG_TYPE, VirtualType.Awaited] : EMPTY_ARRAY);
122137
enqueue(ssr.closeFragment);

0 commit comments

Comments
 (0)