Skip to content

Commit

Permalink
Added NOSERIALIZE_PREFIX to mark the binary strings that is not ser…
Browse files Browse the repository at this point in the history
…ialized.
  • Loading branch information
genki committed Sep 15, 2023
1 parent f3c03e0 commit d16177b
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 5 deletions.
9 changes: 8 additions & 1 deletion packages/qwik/src/core/container/pause.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,12 @@ import {
import { isArray, isObject, isSerializableObject } from '../util/types';
import { directGetAttribute, directSetAttribute } from '../render/fast-calls';
import { isNotNullable, isPromise } from '../util/promises';
import { collectDeps, serializeValue, UNDEFINED_PREFIX } from './serializers';
import {
collectDeps,
serializeValue,
UNDEFINED_PREFIX,
NOSERIALIZE_PREFIX,
} from './serializers';
import {
type ContainerState,
FILTER_REJECT,
Expand Down Expand Up @@ -139,6 +144,7 @@ export const _serializeData = async (data: any, pureQRL?: boolean) => {
}
return obj;
case 'string':
return NOSERIALIZE_PREFIX + obj;
case 'boolean':
return obj;
}
Expand Down Expand Up @@ -482,6 +488,7 @@ export const _pauseFromContexts = async (
}
return obj;
case 'string':
return NOSERIALIZE_PREFIX + obj;
case 'boolean':
return obj;
}
Expand Down
16 changes: 13 additions & 3 deletions packages/qwik/src/core/container/resume.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,13 @@ import { emitEvent } from '../util/event';

import { isArray, isSerializableObject, isString } from '../util/types';
import { directGetAttribute, directSetAttribute } from '../render/fast-calls';
import { createParser, OBJECT_TRANSFORMS, type Parser, UNDEFINED_PREFIX } from './serializers';
import {
createParser,
OBJECT_TRANSFORMS,
type Parser,
UNDEFINED_PREFIX,
NOSERIALIZE_PREFIX,
} from './serializers';
import {
type ContainerState,
_getContainerState,
Expand Down Expand Up @@ -76,7 +82,9 @@ export const _deserializeData = (data: string, element?: unknown) => {
for (let i = 0; i < _objs.length; i++) {
const value = _objs[i];
if (isString(value)) {
_objs[i] = value === UNDEFINED_PREFIX ? undefined : parser.prepare(value);
_objs[i] = value === UNDEFINED_PREFIX ? undefined :
value.startsWith(NOSERIALIZE_PREFIX) ? value.slice(1) :
parser.prepare(value);
}
}

Expand Down Expand Up @@ -228,7 +236,9 @@ export const resumeContainer = (containerEl: Element) => {
assertTrue(objs.length > index, 'resume: index is out of bounds', id);
let value = objs[index];
if (isString(value)) {
value = value === UNDEFINED_PREFIX ? undefined : parser.prepare(value);
value = value === UNDEFINED_PREFIX ? undefined :
value.startsWith(NOSERIALIZE_PREFIX) ? value.slice(1) :
parser.prepare(value);
}
let obj = value;
for (let i = id.length - 1; i >= 0; i--) {
Expand Down
3 changes: 2 additions & 1 deletion packages/qwik/src/core/container/serializers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,8 @@ import { Slot } from '../render/jsx/slot.public';
\': single quote (U+0027 APOSTROPHE)
\\: backslash (U+005C REVERSE SOLIDUS)
*/
export const UNDEFINED_PREFIX = '\u0001';
export const NOSERIALIZE_PREFIX = '\u0000';
export const UNDEFINED_PREFIX = '\u0001';

export interface Serializer<T> {
$prefix$: string;
Expand Down

0 comments on commit d16177b

Please sign in to comment.