Skip to content

Commit 054348d

Browse files
committed
chore: lint++
1 parent 9856df5 commit 054348d

File tree

4 files changed

+24
-25
lines changed

4 files changed

+24
-25
lines changed

packages/qwik/src/core/reactive-primitives/impl/async-signal-impl.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -150,6 +150,7 @@ export class AsyncSignalImpl<T>
150150
}
151151

152152
get untrackedLoading() {
153+
// reading `.loading` means someone is interested in the result, so we should trigger the computation. The alternative is eager computation or imperative calls to invalidate; this seems nicer.
153154
this.$computeIfNeeded$();
154155
// During SSR there's no such thing as loading state, we must render complete results
155156
if ((import.meta.env.TEST ? isServerPlatform() : isServer) && this.$current$?.$promise$) {
@@ -217,12 +218,13 @@ export class AsyncSignalImpl<T>
217218
if (!this.$hasSubscribers$()) {
218219
this.abort();
219220
}
220-
}, 0);
221+
});
221222
}
222223

223224
/** Returns a promise resolves when the signal finished computing. */
224225
async promise(): Promise<void> {
225226
this.$computeIfNeeded$();
227+
// Wait for the current computation to finish, but if we became invalid while running, we need to wait for the new computation instead. So we loop until we are no longer invalid
226228
while (this.$current$?.$promise$) {
227229
await this.$current$?.$promise$;
228230
}

packages/qwik/src/core/shared/serdes/serialize.ts

Lines changed: 5 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -409,20 +409,12 @@ export async function serialize(serializationContext: SerializationContext): Pro
409409
value.$flags$ & SerializationSignalFlags.SERIALIZATION_STRATEGY_NEVER;
410410
const isInvalid = value.$flags$ & SignalFlags.INVALID;
411411
const isSkippable = fastSkipSerialize(value.$untrackedValue$);
412-
const interval =
413-
value instanceof AsyncSignalImpl && value.$interval$ > 0 ? value.$interval$ : undefined;
414-
const concurrency =
415-
value instanceof AsyncSignalImpl && value.$concurrency$ !== 1
416-
? value.$concurrency$
417-
: undefined;
418-
const timeout =
419-
value instanceof AsyncSignalImpl && value.$timeoutMs$ !== 0
420-
? value.$timeoutMs$
421-
: undefined;
412+
const isAsync = value instanceof AsyncSignalImpl;
413+
const interval = isAsync && value.$interval$ > 0 ? value.$interval$ : undefined;
414+
const concurrency = isAsync && value.$concurrency$ !== 1 ? value.$concurrency$ : undefined;
415+
const timeout = isAsync && value.$timeoutMs$ !== 0 ? value.$timeoutMs$ : undefined;
422416
const eagerCleanup =
423-
value instanceof AsyncSignalImpl && value.$flags$ & AsyncSignalFlags.EAGER_CLEANUP
424-
? true
425-
: undefined;
417+
isAsync && value.$flags$ & AsyncSignalFlags.EAGER_CLEANUP ? true : undefined;
426418

427419
if (isInvalid || isSkippable) {
428420
v = NEEDS_COMPUTATION;
@@ -437,7 +429,6 @@ export async function serialize(serializationContext: SerializationContext): Pro
437429
filterEffectBackRefs(value[_EFFECT_BACK_REF]),
438430
value.$effects$,
439431
];
440-
const isAsync = value instanceof AsyncSignalImpl;
441432
if (isAsync) {
442433
// After SSR, the signal is never loading, so no need to send it
443434
out.push(value.$loadingEffects$, value.$errorEffects$, value.$untrackedError$);

packages/qwik/src/core/tests/use-async.spec.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -417,7 +417,7 @@ describe.each([
417417
await trigger(container.element, 'button', 'click');
418418
// on server after resuming cleanup is not called yet
419419
// on client it is called as usual
420-
// so now the log is equal
420+
// so from this point the log is equal for ssr and client
421421
expect((globalThis as any).log).toEqual(['cleanup']);
422422
await trigger(container.element, 'button', 'click'); //show
423423
await trigger(container.element, 'button', 'click'); //hide

packages/qwik/src/server/ssr-container.ts

Lines changed: 15 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -901,23 +901,29 @@ class SSRContainer extends _SharedContainer implements ISSRContainer {
901901
if (!this.serializationCtx.$roots$.length) {
902902
return;
903903
}
904-
const attrs: string[] = ['type', 'qwik/state'];
905904

906-
// Add q-d:qidle attribute if there are signals to eagerly resume
907-
if (this.serializationCtx.$eagerResume$.size > 0) {
908-
const qrl = createQRL(null, '_res', _res, null, [...this.serializationCtx.$eagerResume$]);
909-
const qrlStr = qrlToString(this.serializationCtx, qrl);
910-
attrs.push('q-d:qidle', qrlStr);
911-
// Add 'd:qidle' to event names set
912-
this.serializationCtx.$eventNames$.add('d:qidle');
913-
}
905+
const attrs = this.stateScriptAttrs();
914906

915907
this.openElement('script', null, attrs);
916908
return maybeThen(this.serializationCtx.$serialize$(), () => {
917909
this.closeElement();
918910
});
919911
}
920912

913+
/** Add q-d:qidle attribute to eagerly resume some state if needed */
914+
private stateScriptAttrs(): string[] {
915+
const attrs = ['type', 'qwik/state'];
916+
const eagerResume = this.serializationCtx.$eagerResume$;
917+
if (eagerResume.size > 0) {
918+
const qrl = createQRL(null, '_res', _res, null, [...eagerResume]);
919+
const qrlStr = qrlToString(this.serializationCtx, qrl);
920+
attrs.push('q-d:qidle', qrlStr);
921+
// Add 'd:qidle' to event names set
922+
this.serializationCtx.$eventNames$.add('d:qidle');
923+
}
924+
return attrs;
925+
}
926+
921927
private emitSyncFnsData() {
922928
const fns = this.serializationCtx.$syncFns$;
923929
if (fns.length) {

0 commit comments

Comments
 (0)