diff --git a/.changeset/nasty-planes-jam.md b/.changeset/nasty-planes-jam.md
new file mode 100644
index 00000000000..02fb8bf5b8d
--- /dev/null
+++ b/.changeset/nasty-planes-jam.md
@@ -0,0 +1,9 @@
+---
+'@qwik.dev/core': minor
+---
+
+FEAT: `useSerializer$(fn)` and `createSerializer$(fn)` allow serializing custom objects. You must provide a
+function that converts the custom object to a serializable one via the `[SerializerSymbol]`
+property, and then provide `use|createSerializer$(fn)` with the function that creates the custom object
+from the serialized data. This will lazily create the value when needed. Note that the serializer
+function may return a Promise, which will be awaited. The deserializer must not return a Promise.
diff --git a/.changeset/tricky-peaches-buy.md b/.changeset/tricky-peaches-buy.md
new file mode 100644
index 00000000000..5d3bd106966
--- /dev/null
+++ b/.changeset/tricky-peaches-buy.md
@@ -0,0 +1,8 @@
+---
+'@qwik.dev/core': minor
+---
+
+FEAT: `NoSerializeSymbol`: objects that have this defined will not be serialized
+
+FEAT: `SerializerSymbol`: objects that have this defined as a function will get it called with the object as a parameter during serialization. The function should return the data that should be serialized.
+Use this to remove cached data, consolidate things etc.
diff --git a/packages/docs/src/repl/worker/app-bundle-client.ts b/packages/docs/src/repl/worker/app-bundle-client.ts
index def68d27088..9c4c14a9f2a 100644
--- a/packages/docs/src/repl/worker/app-bundle-client.ts
+++ b/packages/docs/src/repl/worker/app-bundle-client.ts
@@ -55,7 +55,7 @@ export const appBundleClient = async (
const loc = warning.loc;
if (loc && loc.file) {
diagnostic.file = loc.file;
- diagnostic.highlights.push({
+ diagnostic.highlights!.push({
startCol: loc.column,
endCol: loc.column + 1,
startLine: loc.line,
diff --git a/packages/docs/src/repl/worker/app-bundle-ssr.ts b/packages/docs/src/repl/worker/app-bundle-ssr.ts
index 33d08b9f6ae..73940560b1d 100644
--- a/packages/docs/src/repl/worker/app-bundle-ssr.ts
+++ b/packages/docs/src/repl/worker/app-bundle-ssr.ts
@@ -45,7 +45,7 @@ export const appBundleSsr = async (options: ReplInputOptions, result: ReplResult
const loc = warning.loc;
if (loc && loc.file) {
diagnostic.file = loc.file;
- diagnostic.highlights.push({
+ diagnostic.highlights!.push({
startCol: loc.column,
endCol: loc.column + 1,
startLine: loc.line,
diff --git a/packages/docs/src/routes/api/qwik-optimizer/api.json b/packages/docs/src/routes/api/qwik-optimizer/api.json
index 74e41971e41..1e64d0efcb2 100644
--- a/packages/docs/src/routes/api/qwik-optimizer/api.json
+++ b/packages/docs/src/routes/api/qwik-optimizer/api.json
@@ -57,7 +57,7 @@
}
],
"kind": "Interface",
- "content": "```typescript\nexport interface Diagnostic \n```\n\n\n
diff --git a/packages/docs/src/routes/api/qwik/api.json b/packages/docs/src/routes/api/qwik/api.json
index 3595bd3ec82..d93d5efe514 100644
--- a/packages/docs/src/routes/api/qwik/api.json
+++ b/packages/docs/src/routes/api/qwik/api.json
@@ -203,7 +203,7 @@
}
],
"kind": "Function",
- "content": "Create a computed signal which is calculated from the given QRL. A computed signal is a signal which is calculated from other signals. When the signals change, the computed signal is recalculated.\n\nThe QRL must be a function which returns the value of the signal. The function must not have side effects, and it mus be synchronous.\n\nIf you need the function to be async, use `useSignal` and `useTask$` instead.\n\n\n```typescript\ncreateComputed$: (qrl: () => T) => T extends Promise ? never : ComputedSignal\n```\n\n\n
\n\nParameter\n\n\n
\n\nType\n\n\n
\n\nDescription\n\n\n
\n
\n\nqrl\n\n\n
\n\n() => T\n\n\n
\n\n\n
\n
\n**Returns:**\n\nT extends Promise<any> ? never : [ComputedSignal](#computedsignal)<T>",
+ "content": "Create a computed signal which is calculated from the given QRL. A computed signal is a signal which is calculated from other signals. When the signals change, the computed signal is recalculated.\n\nThe QRL must be a function which returns the value of the signal. The function must not have side effects, and it must be synchronous.\n\nIf you need the function to be async, use `useSignal` and `useTask$` instead.\n\n\n```typescript\ncreateComputed$: (qrl: () => T) => T extends Promise ? never : ComputedSignal\n```\n\n\n
\n\nParameter\n\n\n
\n\nType\n\n\n
\n\nDescription\n\n\n
\n
\n\nqrl\n\n\n
\n\n() => T\n\n\n
\n\n\n
\n
\n**Returns:**\n\nT extends Promise<any> ? never : [ComputedSignal](#computedsignal)<T>",
"editUrl": "https://github.com/QwikDev/qwik/tree/main/packages/qwik/src/core/signal/signal.public.ts",
"mdFile": "core.createcomputed_.md"
},
@@ -221,6 +221,20 @@
"editUrl": "https://github.com/QwikDev/qwik/tree/main/packages/qwik/src/core/use/use-context.ts",
"mdFile": "core.createcontextid.md"
},
+ {
+ "name": "createSerializer$",
+ "id": "createserializer_",
+ "hierarchy": [
+ {
+ "name": "createSerializer$",
+ "id": "createserializer_"
+ }
+ ],
+ "kind": "Function",
+ "content": "Create a signal that holds a custom serializable value. See [useSerializer$](#useserializer_) for more details.\n\n\n```typescript\ncreateSerializer$: (arg: SerializerArg) => T extends Promise ? never : SerializerSignal\n```\n\n\n
\n\nParameter\n\n\n
\n\nType\n\n\n
\n\nDescription\n\n\n
\n
\n\narg\n\n\n
\n\nSerializerArg<T, S>\n\n\n
\n\n\n
\n
\n**Returns:**\n\nT extends Promise<any> ? never : SerializerSignal<T>",
+ "editUrl": "https://github.com/QwikDev/qwik/tree/main/packages/qwik/src/core/signal/signal.public.ts",
+ "mdFile": "core.createserializer_.md"
+ },
{
"name": "createSignal",
"id": "createsignal",
@@ -841,6 +855,20 @@
"editUrl": "https://github.com/QwikDev/qwik/tree/main/packages/qwik/src/core/shared/utils/serialize-utils.ts",
"mdFile": "core.noserialize.md"
},
+ {
+ "name": "NoSerializeSymbol",
+ "id": "noserializesymbol",
+ "hierarchy": [
+ {
+ "name": "NoSerializeSymbol",
+ "id": "noserializesymbol"
+ }
+ ],
+ "kind": "Variable",
+ "content": "If an object has this property, it will not be serialized\n\n\n```typescript\nNoSerializeSymbol: unique symbol\n```",
+ "editUrl": "https://github.com/QwikDev/qwik/tree/main/packages/qwik/src/core/shared/utils/serialize-utils.ts",
+ "mdFile": "core.noserializesymbol.md"
+ },
{
"name": "OnRenderFn",
"id": "onrenderfn",
@@ -1541,6 +1569,20 @@
"editUrl": "https://github.com/QwikDev/qwik/tree/main/packages/qwik/src/core/use/use-resource.ts",
"mdFile": "core.resourcereturn.md"
},
+ {
+ "name": "SerializerSymbol",
+ "id": "serializersymbol",
+ "hierarchy": [
+ {
+ "name": "SerializerSymbol",
+ "id": "serializersymbol"
+ }
+ ],
+ "kind": "Variable",
+ "content": "If an object has this property as a function, it will be called with the object and should return a serializable value.\n\nThis can be used to clean up etc.\n\n\n```typescript\nSerializerSymbol: unique symbol\n```",
+ "editUrl": "https://github.com/QwikDev/qwik/tree/main/packages/qwik/src/core/shared/utils/serialize-utils.ts",
+ "mdFile": "core.serializersymbol.md"
+ },
{
"name": "setPlatform",
"id": "setplatform",
@@ -1873,8 +1915,8 @@
}
],
"kind": "Function",
- "content": "Creates a computed signal which is calculated from the given function. A computed signal is a signal which is calculated from other signals. When the signals change, the computed signal is recalculated, and if the result changed, all tasks which are tracking the signal will be re-run and all components that read the signal will be re-rendered.\n\nThe function must be synchronous and must not have any side effects.\n\n\n```typescript\nuseComputed$: (qrl: import(\"./use-computed\").ComputedFn) => T extends Promise ? never : import(\"..\").ReadonlySignal\n```\n\n\n
\n**Returns:**\n\nT extends Promise<any> ? never : import(\"..\").[ReadonlySignal](#readonlysignal)<T>",
- "editUrl": "https://github.com/QwikDev/qwik/tree/main/packages/qwik/src/core/use/use-computed-dollar.ts",
+ "content": "Creates a computed signal which is calculated from the given function. A computed signal is a signal which is calculated from other signals. When the signals change, the computed signal is recalculated, and if the result changed, all tasks which are tracking the signal will be re-run and all components that read the signal will be re-rendered.\n\nThe function must be synchronous and must not have any side effects.\n\n\n```typescript\nuseComputed$: (qrl: ComputedFn) => T extends Promise ? never : ReadonlySignal\n```\n\n\n
\n\nParameter\n\n\n
\n\nType\n\n\n
\n\nDescription\n\n\n
\n
\n\nqrl\n\n\n
\n\n[ComputedFn](#computedfn)<T>\n\n\n
\n\n\n
\n
\n**Returns:**\n\nT extends Promise<any> ? never : [ReadonlySignal](#readonlysignal)<T>",
+ "editUrl": "https://github.com/QwikDev/qwik/tree/main/packages/qwik/src/core/use/use-computed.ts",
"mdFile": "core.usecomputed_.md"
},
{
@@ -2003,6 +2045,20 @@
"editUrl": "https://github.com/QwikDev/qwik/tree/main/packages/qwik/src/core/use/use-resource-dollar.ts",
"mdFile": "core.useresource_.md"
},
+ {
+ "name": "useSerializer$",
+ "id": "useserializer_",
+ "hierarchy": [
+ {
+ "name": "useSerializer$",
+ "id": "useserializer_"
+ }
+ ],
+ "kind": "Variable",
+ "content": "Creates a signal which holds a custom serializable value. It requires that the value implements the `CustomSerializable` type, which means having a function under the `[SerializeSymbol]` property that returns a serializable value when called.\n\nThe `fn` you pass is called with the result of the serialization (in the browser, only when the value is needed), or `undefined` when not yet initialized. If you refer to other signals, `fn` will be called when those change just like computed signals, and then the argument will be the previous output, not the serialized result.\n\nThis is useful when using third party libraries that use custom objects that are not serializable.\n\nNote that the `fn` is called lazily, so it won't impact container resume.\n\n\n```typescript\nuseSerializer$: typeof createSerializer$\n```\n\n\n\n```tsx\nclass MyCustomSerializable {\n constructor(public n: number) {}\n inc() {\n this.n++;\n }\n}\nconst Cmp = component$(() => {\n const custom = useSerializer$({\n deserialize: (data) => new MyCustomSerializable(data),\n serialize: (data) => data.n,\n initial: 2,\n });\n return
custom.value.inc()}>{custom.value.n}
;\n});\n```\n\n\nWhen using a Signal as the data to create the object, you may not need `serialize`. Furthermore, when the signal is updated, the serializer will be updated as well, and the current object will be passed as the second argument.\n\n```tsx\nconst Cmp = component$(() => {\n const n = useSignal(2);\n const custom = useSerializer$((_data, current) => {\n if (current) {\n current.n = n.value;\n return current;\n }\n return new MyCustomSerializable(n.value);\n});\n return
n.value++}>{custom.value.n}
;\n});\n```\n(note that in this example, the `{custom.value.n}` is not reactive, so the div text will not update)",
+ "editUrl": "https://github.com/QwikDev/qwik/tree/main/packages/qwik/src/core/use/use-serialized.ts",
+ "mdFile": "core.useserializer_.md"
+ },
{
"name": "useServerData",
"id": "useserverdata",
diff --git a/packages/docs/src/routes/api/qwik/index.md b/packages/docs/src/routes/api/qwik/index.md
index 769e7349aac..13252d1145d 100644
--- a/packages/docs/src/routes/api/qwik/index.md
+++ b/packages/docs/src/routes/api/qwik/index.md
@@ -603,7 +603,7 @@ Description
Create a computed signal which is calculated from the given QRL. A computed signal is a signal which is calculated from other signals. When the signals change, the computed signal is recalculated.
-The QRL must be a function which returns the value of the signal. The function must not have side effects, and it mus be synchronous.
+The QRL must be a function which returns the value of the signal. The function must not have side effects, and it must be synchronous.
If you need the function to be async, use `useSignal` and `useTask$` instead.
@@ -723,6 +723,45 @@ The name of the context.
[Edit this section](https://github.com/QwikDev/qwik/tree/main/packages/qwik/src/core/use/use-context.ts)
+## createSerializer$
+
+Create a signal that holds a custom serializable value. See [useSerializer$](#useserializer_) for more details.
+
+```typescript
+createSerializer$: (arg: SerializerArg) => T extends Promise ? never : SerializerSignal
+```
+
+
+
+Parameter
+
+
+
+Type
+
+
+
+Description
+
+
+
+
+arg
+
+
+
+SerializerArg<T, S>
+
+
+
+
+
+**Returns:**
+
+T extends Promise<any> ? never : SerializerSignal<T>
+
+[Edit this section](https://github.com/QwikDev/qwik/tree/main/packages/qwik/src/core/signal/signal.public.ts)
+
## createSignal
Creates a Signal with the given value. If no value is given, the signal is created with `undefined`.
@@ -1855,6 +1894,16 @@ export type NoSerialize =
[Edit this section](https://github.com/QwikDev/qwik/tree/main/packages/qwik/src/core/shared/utils/serialize-utils.ts)
+## NoSerializeSymbol
+
+If an object has this property, it will not be serialized
+
+```typescript
+NoSerializeSymbol: unique symbol
+```
+
+[Edit this section](https://github.com/QwikDev/qwik/tree/main/packages/qwik/src/core/shared/utils/serialize-utils.ts)
+
## OnRenderFn
```typescript
@@ -3549,6 +3598,18 @@ export type ResourceReturn =
[Edit this section](https://github.com/QwikDev/qwik/tree/main/packages/qwik/src/core/use/use-resource.ts)
+## SerializerSymbol
+
+If an object has this property as a function, it will be called with the object and should return a serializable value.
+
+This can be used to clean up etc.
+
+```typescript
+SerializerSymbol: unique symbol
+```
+
+[Edit this section](https://github.com/QwikDev/qwik/tree/main/packages/qwik/src/core/shared/utils/serialize-utils.ts)
+
## setPlatform
Sets the `CorePlatform`.
@@ -4394,7 +4455,7 @@ Creates a computed signal which is calculated from the given function. A compute
The function must be synchronous and must not have any side effects.
```typescript
-useComputed$: (qrl: import("./use-computed").ComputedFn) => T extends Promise ? never : import("..").ReadonlySignal
+useComputed$: (qrl: ComputedFn) => T extends Promise ? never : ReadonlySignal
```
**Returns:**
-T extends Promise<any> ? never : import("..").[ReadonlySignal](#readonlysignal)<T>
+T extends Promise<any> ? never : [ReadonlySignal](#readonlysignal)<T>
-[Edit this section](https://github.com/QwikDev/qwik/tree/main/packages/qwik/src/core/use/use-computed-dollar.ts)
+[Edit this section](https://github.com/QwikDev/qwik/tree/main/packages/qwik/src/core/use/use-computed.ts)
## useConstant
@@ -4883,6 +4944,57 @@ _(Optional)_
[Edit this section](https://github.com/QwikDev/qwik/tree/main/packages/qwik/src/core/use/use-resource-dollar.ts)
+## useSerializer$
+
+Creates a signal which holds a custom serializable value. It requires that the value implements the `CustomSerializable` type, which means having a function under the `[SerializeSymbol]` property that returns a serializable value when called.
+
+The `fn` you pass is called with the result of the serialization (in the browser, only when the value is needed), or `undefined` when not yet initialized. If you refer to other signals, `fn` will be called when those change just like computed signals, and then the argument will be the previous output, not the serialized result.
+
+This is useful when using third party libraries that use custom objects that are not serializable.
+
+Note that the `fn` is called lazily, so it won't impact container resume.
+
+```typescript
+useSerializer$: typeof createSerializer$;
+```
+
+```tsx
+class MyCustomSerializable {
+ constructor(public n: number) {}
+ inc() {
+ this.n++;
+ }
+}
+const Cmp = component$(() => {
+ const custom = useSerializer$({
+ deserialize: (data) => new MyCustomSerializable(data),
+ serialize: (data) => data.n,
+ initial: 2,
+ });
+ return
custom.value.inc()}>{custom.value.n}
;
+});
+```
+
+When using a Signal as the data to create the object, you may not need `serialize`. Furthermore, when the signal is updated, the serializer will be updated as well, and the current object will be passed as the second argument.
+
+```tsx
+const Cmp = component$(() => {
+ const n = useSignal(2);
+ const custom = useSerializer$((_data, current) => {
+ if (current) {
+ current.n = n.value;
+ return current;
+ }
+ return new MyCustomSerializable(n.value);
+ });
+ return
n.value++}>{custom.value.n}
;
+});
+```
+
+(note that in this example, the `{custom.value.n}` is not reactive, so the div text will not update)
+
+[Edit this section](https://github.com/QwikDev/qwik/tree/main/packages/qwik/src/core/use/use-serialized.ts)
+
## useServerData
```typescript
diff --git a/packages/qwik/public.d.ts b/packages/qwik/public.d.ts
index 0208f05569b..8c931183e4d 100644
--- a/packages/qwik/public.d.ts
+++ b/packages/qwik/public.d.ts
@@ -6,6 +6,7 @@ export {
ComputedSignal,
ContextId,
createComputed$,
+ createSerializer$,
createContextId,
createSignal,
CSSProperties,
@@ -60,6 +61,7 @@ export {
useOnDocument,
useOnWindow,
useResource$,
+ useSerializer$,
useServerData,
useSignal,
useStore,
diff --git a/packages/qwik/src/core/api.md b/packages/qwik/src/core/api.md
index 95487f0d77a..bcc193cfc99 100644
--- a/packages/qwik/src/core/api.md
+++ b/packages/qwik/src/core/api.md
@@ -111,14 +111,31 @@ export interface CorrectedToggleEvent extends Event {
// @public
export const createComputed$: (qrl: () => T) => T extends Promise ? never : ComputedSignal;
+// Warning: (ae-forgotten-export) The symbol "ComputedSignal_2" needs to be exported by the entry point index.d.ts
// Warning: (ae-internal-missing-underscore) The name "createComputedQrl" should be prefixed with an underscore because the declaration is marked as @internal
//
// @internal (undocumented)
-export const createComputedQrl: (qrl: QRL<() => T>) => T extends Promise ? never : ComputedSignal;
+export const createComputedQrl: (qrl: QRL<() => T>) => ComputedSignal_2;
// @public
export const createContextId: (name: string) => ContextId;
+// Warning: (ae-forgotten-export) The symbol "SerializerArg" needs to be exported by the entry point index.d.ts
+// Warning: (ae-forgotten-export) The symbol "SerializerSignal" needs to be exported by the entry point index.d.ts
+//
+// @public
+export const createSerializer$: (arg: SerializerArg) => T extends Promise ? never : SerializerSignal;
+
+// Warning: (ae-forgotten-export) The symbol "SerializerSignal_2" needs to be exported by the entry point index.d.ts
+// Warning: (ae-internal-missing-underscore) The name "createSerializerQrl" should be prefixed with an underscore because the declaration is marked as @internal
+//
+// @internal (undocumented)
+export const createSerializerQrl: (arg: QRL<{
+ serialize: (data: S | undefined) => T;
+ deserialize: (data: T) => S;
+ initial?: S;
+}>) => SerializerSignal_2;
+
// @public
export const createSignal: {
(): Signal;
@@ -498,6 +515,9 @@ export type NoSerialize = (T & {
// @public
export const noSerialize: (input: T) => NoSerialize;
+// @public
+export const NoSerializeSymbol: unique symbol;
+
// @public (undocumented)
export type OnRenderFn = (props: PROPS) => JSXOutput;
@@ -811,6 +831,9 @@ export const _restProps: (props: Record, omit: string[], target?: {
// @internal
export function _serialize(data: unknown[]): Promise;
+// @public
+export const SerializerSymbol: unique symbol;
+
// @public
export const setPlatform: (plt: CorePlatform) => CorePlatform;
@@ -1086,6 +1109,14 @@ export const useResource$: (generatorFn: ResourceFn, opts?: ResourceOption
// @internal (undocumented)
export const useResourceQrl: (qrl: QRL>, opts?: ResourceOptions) => ResourceReturn;
+// @public
+export const useSerializer$: typeof createSerializer$;
+
+// Warning: (ae-internal-missing-underscore) The name "useSerializerQrl" should be prefixed with an underscore because the declaration is marked as @internal
+//
+// @internal (undocumented)
+export const useSerializerQrl: (qrl: QRL>) => ReadonlySignal;
+
// @public (undocumented)
export function useServerData(key: string): T | undefined;
diff --git a/packages/qwik/src/core/index.ts b/packages/qwik/src/core/index.ts
index 9ae8ab7acf2..31e6256a233 100644
--- a/packages/qwik/src/core/index.ts
+++ b/packages/qwik/src/core/index.ts
@@ -110,6 +110,7 @@ export type { ContextId } from './use/use-context';
export type { UseStoreOptions } from './use/use-store.public';
export type { ComputedFn } from './use/use-computed';
export { useComputedQrl } from './use/use-computed';
+export { useSerializerQrl, useSerializer$ } from './use/use-serialized';
export type { OnVisibleTaskOptions, VisibleTaskStrategy } from './use/use-visible-task';
export { useVisibleTaskQrl } from './use/use-visible-task';
export type { EagernessOptions, TaskCtx, TaskFn, Tracker, UseTaskOptions } from './use/use-task';
@@ -128,18 +129,29 @@ export { useResource$ } from './use/use-resource-dollar';
export { useTaskQrl } from './use/use-task';
export { useTask$ } from './use/use-task-dollar';
export { useVisibleTask$ } from './use/use-visible-task-dollar';
-export { useComputed$ } from './use/use-computed-dollar';
+export { useComputed$ } from './use/use-computed';
export { useErrorBoundary } from './use/use-error-boundary';
export type { ErrorBoundaryStore } from './shared/error/error-handling';
export { type ReadonlySignal, type Signal, type ComputedSignal } from './signal/signal.public';
-export { isSignal, createSignal, createComputedQrl, createComputed$ } from './signal/signal.public';
+export {
+ isSignal,
+ createSignal,
+ createComputedQrl,
+ createComputed$,
+ createSerializerQrl,
+ createSerializer$,
+} from './signal/signal.public';
export { EffectPropData as _EffectData } from './signal/signal';
//////////////////////////////////////////////////////////////////////////////////////////
// Developer Low-Level API
//////////////////////////////////////////////////////////////////////////////////////////
export type { ValueOrPromise } from './shared/utils/types';
-export { type NoSerialize } from './shared/utils/serialize-utils';
+export {
+ NoSerializeSymbol,
+ SerializerSymbol,
+ type NoSerialize,
+} from './shared/utils/serialize-utils';
export { noSerialize } from './shared/utils/serialize-utils';
export { version } from './version';
diff --git a/packages/qwik/src/core/shared/error/error.ts b/packages/qwik/src/core/shared/error/error.ts
index 409a03042f4..9ad201bcf8c 100644
--- a/packages/qwik/src/core/shared/error/error.ts
+++ b/packages/qwik/src/core/shared/error/error.ts
@@ -56,6 +56,7 @@ export const codeToText = (code: number, ...parts: any[]): string => {
'WrappedSignal is read-only', // 49
'SsrError: Promises not expected here.', // 50
'Attribute value is unsafe for SSR', // 51
+ 'SerializerSymbol function returned rejected promise', // 52
];
let text = MAP[code] ?? '';
if (parts.length) {
@@ -126,6 +127,7 @@ export const enum QError {
wrappedReadOnly = 48,
promisesNotExpected = 49,
unsafeAttr = 50,
+ serializerSymbolRejectedPromise = 52,
}
export const qError = (code: number, errorMessageArgs: any[] = []): Error => {
diff --git a/packages/qwik/src/core/shared/serialization.md b/packages/qwik/src/core/shared/serialization.md
index 3a136193f31..9cb3d414239 100644
--- a/packages/qwik/src/core/shared/serialization.md
+++ b/packages/qwik/src/core/shared/serialization.md
@@ -37,3 +37,17 @@ To avoid blocking the main thread on wake, we lazily restore the roots, with cac
The serialized text is first parsed to get an array of encoded root data.
Then, a proxy gets the raw data and returns an array that deserializes properties on demand and caches them. Objects are also lazily restored.
+
+## Out-of-order streaming
+
+when we allow out-of-order streaming but we want interactivity while the page is still streaming, we can't scan the state once for cycles/Promises/references, because later state might refer to earlier state.
+
+Therefore we must make the serializer single-pass. To do this, we could store each object as a root, but that will make references take more bytes. Instead, we could implement sub-paths for references, and when we encounter a reference, we output that instead.
+
+For later references it would be best to have a root reference, so we'd probably add a root for the sub-reference and later we can refer to that.
+
+We'll still need to keep track of Promises. We can do this by waiting, but that halts streaming. Instead, we could write a forward reference id, and when the promise is resolved, we store the result as the next root item. At the end of the stream we can emit a mapping from forward references to root index.
+
+Then later, when we send out-of-order state, it will append to the existing state on the client.
+
+This single-pass approach might just be better in general, because several bugs were found due to differences between the first and second pass code, and it allows streaming the data while the promises are being resolved.
diff --git a/packages/qwik/src/core/shared/shared-serialization.ts b/packages/qwik/src/core/shared/shared-serialization.ts
index 2f41639f106..6e77c6b0a09 100644
--- a/packages/qwik/src/core/shared/shared-serialization.ts
+++ b/packages/qwik/src/core/shared/shared-serialization.ts
@@ -8,7 +8,16 @@ import { type DomContainer } from '../client/dom-container';
import type { VNode } from '../client/types';
import { vnode_getNode, vnode_isVNode, vnode_locate, vnode_toString } from '../client/vnode';
import { NEEDS_COMPUTATION } from '../signal/flags';
-import { ComputedSignal, EffectPropData, Signal, WrappedSignal } from '../signal/signal';
+import {
+ ComputedSignal,
+ EffectPropData,
+ SerializerSignal,
+ Signal,
+ WrappedSignal,
+ isSerializerObj,
+ type EffectSubscriptions,
+ type SerializerArg,
+} from '../signal/signal';
import type { Subscriber } from '../signal/signal-subscriber';
import {
STORE_ARRAY_PROP,
@@ -48,7 +57,7 @@ import { isElement, isNode } from './utils/element';
import { EMPTY_ARRAY, EMPTY_OBJ } from './utils/flyweight';
import { ELEMENT_ID, ELEMENT_KEY } from './utils/markers';
import { isPromise } from './utils/promises';
-import { fastSkipSerialize } from './utils/serialize-utils';
+import { SerializerSymbol, fastSkipSerialize } from './utils/serialize-utils';
import { type ValueOrPromise } from './utils/types';
const deserializedProxyMap = new WeakMap