Skip to content

Commit 3e78fae

Browse files
committed
refactor(scheduler): remove COMPONENT_SSR type
1 parent ec7e9b2 commit 3e78fae

File tree

7 files changed

+39
-139
lines changed

7 files changed

+39
-139
lines changed

packages/docs/src/routes/api/qwik/api.json

Lines changed: 1 addition & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -277,20 +277,6 @@
277277
"editUrl": "https://github.com/QwikDev/qwik/tree/main/packages/qwik/src/core/shared/jsx/types/jsx-qwik-attributes.ts",
278278
"mdFile": "core.domattributes.md"
279279
},
280-
{
281-
"name": "EagernessOptions",
282-
"id": "eagernessoptions",
283-
"hierarchy": [
284-
{
285-
"name": "EagernessOptions",
286-
"id": "eagernessoptions"
287-
}
288-
],
289-
"kind": "TypeAlias",
290-
"content": "```typescript\nexport type EagernessOptions = 'visible' | 'load' | 'idle';\n```",
291-
"editUrl": "https://github.com/QwikDev/qwik/tree/main/packages/qwik/src/core/use/use-task.ts",
292-
"mdFile": "core.eagernessoptions.md"
293-
},
294280
{
295281
"name": "Element",
296282
"id": "qwikjsx-element",
@@ -2125,24 +2111,10 @@
21252111
}
21262112
],
21272113
"kind": "Function",
2128-
"content": "Reruns the `taskFn` when the observed inputs change.\n\nUse `useTask` to observe changes on a set of inputs, and then re-execute the `taskFn` when those inputs change.\n\nThe `taskFn` only executes if the observed inputs change. To observe the inputs, use the `obs` function to wrap property reads. This creates subscriptions that will trigger the `taskFn` to rerun.\n\n\n```typescript\nuseTask$: (qrl: import(\"./use-task\").TaskFn, opts?: import(\"./use-task\").UseTaskOptions | undefined) => void\n```\n\n\n<table><thead><tr><th>\n\nParameter\n\n\n</th><th>\n\nType\n\n\n</th><th>\n\nDescription\n\n\n</th></tr></thead>\n<tbody><tr><td>\n\nqrl\n\n\n</td><td>\n\nimport(\"./use-task\").[TaskFn](#taskfn)\n\n\n</td><td>\n\n\n</td></tr>\n<tr><td>\n\nopts\n\n\n</td><td>\n\nimport(\"./use-task\").[UseTaskOptions](#usetaskoptions) \\| undefined\n\n\n</td><td>\n\n_(Optional)_\n\n\n</td></tr>\n</tbody></table>\n**Returns:**\n\nvoid",
2114+
"content": "Reruns the `taskFn` when the observed inputs change.\n\nUse `useTask` to observe changes on a set of inputs, and then re-execute the `taskFn` when those inputs change.\n\nThe `taskFn` only executes if the observed inputs change. To observe the inputs, use the `obs` function to wrap property reads. This creates subscriptions that will trigger the `taskFn` to rerun.\n\n\n```typescript\nuseTask$: (qrl: import(\"./use-task\").TaskFn) => void\n```\n\n\n<table><thead><tr><th>\n\nParameter\n\n\n</th><th>\n\nType\n\n\n</th><th>\n\nDescription\n\n\n</th></tr></thead>\n<tbody><tr><td>\n\nqrl\n\n\n</td><td>\n\nimport(\"./use-task\").[TaskFn](#taskfn)\n\n\n</td><td>\n\n\n</td></tr>\n</tbody></table>\n**Returns:**\n\nvoid",
21292115
"editUrl": "https://github.com/QwikDev/qwik/tree/main/packages/qwik/src/core/use/use-task-dollar.ts",
21302116
"mdFile": "core.usetask_.md"
21312117
},
2132-
{
2133-
"name": "UseTaskOptions",
2134-
"id": "usetaskoptions",
2135-
"hierarchy": [
2136-
{
2137-
"name": "UseTaskOptions",
2138-
"id": "usetaskoptions"
2139-
}
2140-
],
2141-
"kind": "Interface",
2142-
"content": "```typescript\nexport interface UseTaskOptions \n```\n\n\n<table><thead><tr><th>\n\nProperty\n\n\n</th><th>\n\nModifiers\n\n\n</th><th>\n\nType\n\n\n</th><th>\n\nDescription\n\n\n</th></tr></thead>\n<tbody><tr><td>\n\n[eagerness?](#)\n\n\n</td><td>\n\n\n</td><td>\n\n[EagernessOptions](#eagernessoptions)\n\n\n</td><td>\n\n_(Optional)_ - `visible`<!-- -->: run the effect when the element is visible. - `load`<!-- -->: eagerly run the effect when the application resumes.\n\n\n</td></tr>\n</tbody></table>",
2143-
"editUrl": "https://github.com/QwikDev/qwik/tree/main/packages/qwik/src/core/use/use-task.ts",
2144-
"mdFile": "core.usetaskoptions.md"
2145-
},
21462118
{
21472119
"name": "useVisibleTask$",
21482120
"id": "usevisibletask_",

packages/docs/src/routes/api/qwik/index.md

Lines changed: 1 addition & 64 deletions
Original file line numberDiff line numberDiff line change
@@ -873,14 +873,6 @@ _(Optional)_
873873
874874
[Edit this section](https://github.com/QwikDev/qwik/tree/main/packages/qwik/src/core/shared/jsx/types/jsx-qwik-attributes.ts)
875875
876-
## EagernessOptions
877-
878-
```typescript
879-
export type EagernessOptions = "visible" | "load" | "idle";
880-
```
881-
882-
[Edit this section](https://github.com/QwikDev/qwik/tree/main/packages/qwik/src/core/use/use-task.ts)
883-
884876
## Element
885877
886878
```typescript
@@ -5252,7 +5244,7 @@ Use `useTask` to observe changes on a set of inputs, and then re-execute the `ta
52525244
The `taskFn` only executes if the observed inputs change. To observe the inputs, use the `obs` function to wrap property reads. This creates subscriptions that will trigger the `taskFn` to rerun.
52535245
52545246
```typescript
5255-
useTask$: (qrl: import("./use-task").TaskFn, opts?: import("./use-task").UseTaskOptions | undefined) => void
5247+
useTask$: (qrl: import("./use-task").TaskFn) => void
52565248
```
52575249
52585250
<table><thead><tr><th>
@@ -5278,19 +5270,6 @@ import("./use-task").[TaskFn](#taskfn)
52785270
52795271
</td><td>
52805272
5281-
</td></tr>
5282-
<tr><td>
5283-
5284-
opts
5285-
5286-
</td><td>
5287-
5288-
import("./use-task").[UseTaskOptions](#usetaskoptions) \| undefined
5289-
5290-
</td><td>
5291-
5292-
_(Optional)_
5293-
52945273
</td></tr>
52955274
</tbody></table>
52965275
**Returns:**
@@ -5299,48 +5278,6 @@ void
52995278
53005279
[Edit this section](https://github.com/QwikDev/qwik/tree/main/packages/qwik/src/core/use/use-task-dollar.ts)
53015280
5302-
## UseTaskOptions
5303-
5304-
```typescript
5305-
export interface UseTaskOptions
5306-
```
5307-
5308-
<table><thead><tr><th>
5309-
5310-
Property
5311-
5312-
</th><th>
5313-
5314-
Modifiers
5315-
5316-
</th><th>
5317-
5318-
Type
5319-
5320-
</th><th>
5321-
5322-
Description
5323-
5324-
</th></tr></thead>
5325-
<tbody><tr><td>
5326-
5327-
[eagerness?](#)
5328-
5329-
</td><td>
5330-
5331-
</td><td>
5332-
5333-
[EagernessOptions](#eagernessoptions)
5334-
5335-
</td><td>
5336-
5337-
_(Optional)_ - `visible`: run the effect when the element is visible. - `load`: eagerly run the effect when the application resumes.
5338-
5339-
</td></tr>
5340-
</tbody></table>
5341-
5342-
[Edit this section](https://github.com/QwikDev/qwik/tree/main/packages/qwik/src/core/use/use-task.ts)
5343-
53445281
## useVisibleTask$
53455282
53465283
```tsx

packages/qwik/src/core/api.md

Lines changed: 3 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -217,9 +217,6 @@ class DomContainer extends _SharedContainer implements ClientContainer {
217217
export { DomContainer }
218218
export { DomContainer as _DomContainer }
219219

220-
// @public (undocumented)
221-
export type EagernessOptions = 'visible' | 'load' | 'idle';
222-
223220
// @internal (undocumented)
224221
export class _EffectData {
225222
constructor(data: NodePropData);
@@ -1140,17 +1137,12 @@ export interface UseStylesScoped {
11401137
export const useStylesScopedQrl: (styles: QRL<string>) => UseStylesScoped;
11411138

11421139
// @public
1143-
export const useTask$: (qrl: TaskFn, opts?: UseTaskOptions | undefined) => void;
1144-
1145-
// @public (undocumented)
1146-
export interface UseTaskOptions {
1147-
eagerness?: EagernessOptions;
1148-
}
1140+
export const useTask$: (qrl: TaskFn) => void;
11491141

11501142
// Warning: (ae-internal-missing-underscore) The name "useTaskQrl" should be prefixed with an underscore because the declaration is marked as @internal
11511143
//
11521144
// @internal (undocumented)
1153-
export const useTaskQrl: (qrl: QRL<TaskFn>, opts?: UseTaskOptions) => void;
1145+
export const useTaskQrl: (qrl: QRL<TaskFn>) => void;
11541146

11551147
// @public
11561148
export const useVisibleTask$: (qrl: TaskFn, opts?: OnVisibleTaskOptions | undefined) => void;
@@ -1237,17 +1229,9 @@ export const _waitUntilRendered: (elm: Element) => Promise<void>;
12371229
//
12381230
// @internal (undocumented)
12391231
export function _walkJSX(ssr: SSRContainer, value: JSXOutput, options: {
1240-
allowPromises: true;
1241-
currentStyleScoped: string | null;
1242-
parentComponentFrame: ISsrComponentFrame | null;
1243-
}): ValueOrPromise<void>;
1244-
1245-
// @internal (undocumented)
1246-
export function _walkJSX(ssr: SSRContainer, value: JSXOutput, options: {
1247-
allowPromises: false;
12481232
currentStyleScoped: string | null;
12491233
parentComponentFrame: ISsrComponentFrame | null;
1250-
}): false;
1234+
}): Promise<void>;
12511235

12521236
// @internal (undocumented)
12531237
export const _weakSerialize: <T extends object>(input: T) => Partial<T>;

packages/qwik/src/core/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,7 @@ export type { ComputedFn } from './use/use-computed';
112112
export { useComputedQrl } from './use/use-computed';
113113
export type { OnVisibleTaskOptions, VisibleTaskStrategy } from './use/use-visible-task';
114114
export { useVisibleTaskQrl } from './use/use-visible-task';
115-
export type { EagernessOptions, TaskCtx, TaskFn, Tracker, UseTaskOptions } from './use/use-task';
115+
export type { TaskCtx, TaskFn, Tracker } from './use/use-task';
116116
export type {
117117
ResourceProps,
118118
ResourceOptions,

packages/qwik/src/core/shared/scheduler.ts

Lines changed: 31 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,7 @@ import type { OnRenderFn } from './component.public';
102102
import { assertEqual } from './error/assert';
103103
import type { Props } from './jsx/jsx-runtime';
104104
import type { JSXOutput } from './jsx/types/jsx-node';
105-
import type { QRLInternal } from './qrl/qrl-class';
105+
import { emitEvent, type QRLInternal } from './qrl/qrl-class';
106106
import { ssrNodeDocumentPosition, vnode_documentPosition } from './scheduler-document-position';
107107
import type { Container, HostElement } from './types';
108108
import { logWarn } from './utils/log';
@@ -128,7 +128,6 @@ export const enum ChoreType {
128128
TASK,
129129
NODE_DIFF,
130130
NODE_PROP,
131-
COMPONENT_SSR,
132131
COMPONENT,
133132
RECOMPUTE_AND_SCHEDULE_EFFECTS,
134133

@@ -218,7 +217,7 @@ export const createScheduler = (
218217
args: unknown[]
219218
): ValueOrPromise<void>;
220219
function schedule(
221-
type: ChoreType.COMPONENT | ChoreType.COMPONENT_SSR,
220+
type: ChoreType.COMPONENT,
222221
host: HostElement,
223222
qrl: QRLInternal<OnRenderFn<unknown>>,
224223
props: Props | null
@@ -243,15 +242,22 @@ export const createScheduler = (
243242
targetOrQrl: ChoreTarget | string | null = null,
244243
payload: any = null
245244
): ValueOrPromise<any> {
245+
const isServer = !isDomContainer(container);
246+
const isComponentSsr = isServer && type === ChoreType.COMPONENT;
247+
246248
const runLater: boolean =
247-
type !== ChoreType.WAIT_FOR_ALL &&
248-
type !== ChoreType.COMPONENT_SSR &&
249-
type !== ChoreType.RUN_QRL;
249+
type !== ChoreType.WAIT_FOR_ALL && !isComponentSsr && type !== ChoreType.RUN_QRL;
250250
const isTask =
251251
type === ChoreType.TASK ||
252252
type === ChoreType.VISIBLE ||
253253
type === ChoreType.RESOURCE ||
254254
type === ChoreType.CLEANUP_VISIBLE;
255+
const isClientOnly =
256+
type === ChoreType.JOURNAL_FLUSH ||
257+
type === ChoreType.RECOMPUTE_AND_SCHEDULE_EFFECTS ||
258+
type === ChoreType.NODE_DIFF ||
259+
type === ChoreType.NODE_PROP;
260+
255261
if (isTask) {
256262
(hostOrTask as Task).$flags$ |= TaskFlags.DIRTY;
257263
}
@@ -271,7 +277,10 @@ export const createScheduler = (
271277
$executed$: false,
272278
};
273279
DEBUG && debugTrace('schedule', chore, currentChore, choreQueue);
274-
chore = sortedInsert(choreQueue, chore, (container as DomContainer).rootVNode || null);
280+
// add only if client or server and is not client only chore
281+
if (!isServer || !isClientOnly) {
282+
chore = sortedInsert(choreQueue, chore, (container as DomContainer).rootVNode || null);
283+
}
275284
if (!journalFlushScheduled && runLater) {
276285
// If we are not currently draining, we need to schedule a drain.
277286
journalFlushScheduled = true;
@@ -281,7 +290,7 @@ export const createScheduler = (
281290
if (runLater) {
282291
return getPromise(chore);
283292
} else {
284-
return drainUpTo(chore);
293+
return drainUpTo(chore, isServer);
285294
}
286295
}
287296

@@ -290,11 +299,17 @@ export const createScheduler = (
290299
*
291300
* @param runUptoChore
292301
*/
293-
function drainUpTo(runUptoChore: Chore): ValueOrPromise<unknown> {
302+
function drainUpTo(runUptoChore: Chore, isServer: boolean): ValueOrPromise<unknown> {
294303
while (choreQueue.length) {
295304
if (currentChore) {
296305
// Already running chore, which means we're waiting for async completion
297-
return getPromise(currentChore).then(() => drainUpTo(runUptoChore));
306+
return getPromise(currentChore)
307+
.then(() => drainUpTo(runUptoChore, isServer))
308+
.catch((error) => {
309+
currentChore = null;
310+
emitEvent('qerror', { error });
311+
return drainUpTo(runUptoChore, isServer);
312+
});
298313
}
299314
const nextChore = choreQueue.shift()!;
300315
const isDeletedVNode = vNodeAlreadyDeleted(nextChore);
@@ -306,15 +321,15 @@ export const createScheduler = (
306321
DEBUG && debugTrace('skip chore', nextChore, currentChore, choreQueue);
307322
continue;
308323
}
309-
executeChore(nextChore);
324+
executeChore(nextChore, isServer);
310325
if (nextChore === runUptoChore) {
311326
break;
312327
}
313328
}
314329
return runUptoChore.$executed$ ? runUptoChore.$returnValue$ : getPromise(runUptoChore);
315330
}
316331

317-
function executeChore(chore: Chore): ValueOrPromise<any> {
332+
function executeChore(chore: Chore, isServer: boolean): ValueOrPromise<any> {
318333
const host = chore.$host$;
319334
DEBUG && debugTrace('execute', chore, currentChore, choreQueue);
320335
assertEqual(currentChore, null, 'Chore already running.');
@@ -326,7 +341,6 @@ export const createScheduler = (
326341
journalFlushScheduled = false;
327342
break;
328343
case ChoreType.COMPONENT:
329-
case ChoreType.COMPONENT_SSR:
330344
returnValue = safeCall(
331345
() =>
332346
executeComponent(
@@ -337,7 +351,9 @@ export const createScheduler = (
337351
chore.$payload$ as Props | null
338352
),
339353
(jsx) => {
340-
if (chore.$type$ === ChoreType.COMPONENT) {
354+
if (isServer) {
355+
return jsx;
356+
} else {
341357
const styleScopedId = container.getHostProp<string>(host, QScopedStyle);
342358
return retryOnPromise(() =>
343359
vnode_diff(
@@ -347,8 +363,6 @@ export const createScheduler = (
347363
addComponentStylePrefix(styleScopedId)
348364
)
349365
);
350-
} else {
351-
return jsx;
352366
}
353367
},
354368
(err: any) => container.handleError(err, host)
@@ -365,7 +379,7 @@ export const createScheduler = (
365379
container,
366380
host
367381
);
368-
returnValue = isDomContainer(container) ? null : result;
382+
returnValue = isServer ? result : null;
369383
}
370384
break;
371385
case ChoreType.RUN_QRL:
@@ -595,7 +609,6 @@ function debugChoreToString(chore: Chore): string {
595609
[ChoreType.NODE_DIFF]: 'NODE_DIFF',
596610
[ChoreType.NODE_PROP]: 'NODE_PROP',
597611
[ChoreType.COMPONENT]: 'COMPONENT',
598-
[ChoreType.COMPONENT_SSR]: 'COMPONENT_SSR',
599612
[ChoreType.RECOMPUTE_AND_SCHEDULE_EFFECTS]: 'RECOMPUTE_SIGNAL',
600613
[ChoreType.JOURNAL_FLUSH]: 'JOURNAL_FLUSH',
601614
[ChoreType.VISIBLE]: 'VISIBLE',

packages/qwik/src/core/signal/signal.ts

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,6 @@ import type { Props } from '../shared/jsx/jsx-runtime';
3232
import type { OnRenderFn } from '../shared/component.public';
3333
import { NEEDS_COMPUTATION } from './flags';
3434
import { QError, qError } from '../shared/error/error';
35-
import { isDomContainer } from '../client/dom-container';
3635

3736
const DEBUG = false;
3837

@@ -351,12 +350,7 @@ export const triggerEffects = (
351350
const qrl = container.getHostProp<QRLInternal<OnRenderFn<unknown>>>(host, OnRenderProp);
352351
assertDefined(qrl, 'Component must have QRL');
353352
const props = container.getHostProp<Props>(host, ELEMENT_PROPS);
354-
container.$scheduler$(
355-
isDomContainer(container) ? ChoreType.COMPONENT : ChoreType.COMPONENT_SSR,
356-
host,
357-
qrl,
358-
props
359-
);
353+
container.$scheduler$(ChoreType.COMPONENT, host, qrl, props);
360354
} else if (property === EffectProperty.VNODE) {
361355
const host: HostElement = effect as any;
362356
const target = host;

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,5 +35,5 @@ export const applyQwikComponentBody = (
3535
if (jsx.key !== null) {
3636
host.setProp(ELEMENT_KEY, jsx.key);
3737
}
38-
return scheduler(ChoreType.COMPONENT_SSR, host, componentQrl, srcProps);
38+
return scheduler(ChoreType.COMPONENT, host, componentQrl, srcProps);
3939
};

0 commit comments

Comments
 (0)