Skip to content

Commit

Permalink
change deserialize method
Browse files Browse the repository at this point in the history
  • Loading branch information
Varixo committed Aug 4, 2024
1 parent 77206e1 commit a94c826
Showing 1 changed file with 15 additions and 11 deletions.
26 changes: 15 additions & 11 deletions packages/qwik/src/core/v2/shared/shared-serialization.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1264,41 +1264,45 @@ export async function _serialize(data: unknown): Promise<string> {
/** @internal */
export function _deserialize(rawStateData: string, element?: unknown): unknown[] | unknown {
const stateData = JSON.parse(rawStateData);
if (!Array.isArray(stateData)) {
return null;
}

let container: DomContainer | undefined = undefined;
if (isNode(element) && isElement(element)) {
container = getDomContainer(element) as DomContainer;
}
if (!Array.isArray(stateData)) {
return deserializeData([], stateData, container);
}
for (let i = 0; i < stateData.length; i++) {
const data = stateData[i];
stateData[i] = deserializeData(stateData, data, container);
}
return stateData;
}

function deserializeData(stateData: unknown[], data: string, container?: DeserializeContainer) {
function deserializeData(
stateData: unknown[],
serializedData: string,
container?: DeserializeContainer
) {
let typeCode: number;
if (
typeof data === 'string' &&
data.length >= 1 &&
(typeCode = data.charCodeAt(0)) < SerializationConstant.LAST_VALUE
typeof serializedData === 'string' &&
serializedData.length >= 1 &&
(typeCode = serializedData.charCodeAt(0)) < SerializationConstant.LAST_VALUE
) {
let propValue = data;
let propValue = serializedData;
propValue = allocate(propValue);

if (typeCode >= SerializationConstant.Error_VALUE) {
if (container) {
inflate(container, propValue, data);
inflate(container, propValue, serializedData);
} else {
inflateWithoutContainer(propValue, data, stateData);
inflateWithoutContainer(propValue, serializedData, stateData);
}
}
return propValue;
}
return data;
return serializedData;
}

const inflateWithoutContainer = (target: any, needsInflationData: string, stateData: unknown[]) => {
Expand Down

0 comments on commit a94c826

Please sign in to comment.