Skip to content

Commit 9500039

Browse files
committed
ignore functions with NoSerializeSymbol
1 parent 6c4bd10 commit 9500039

File tree

2 files changed

+16
-2
lines changed

2 files changed

+16
-2
lines changed

packages/qwik/src/core/shared/shared-serialization.unit.ts

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -955,6 +955,20 @@ describe('shared-serialization', () => {
955955
(17 chars)"
956956
`);
957957
});
958+
it('should ignore functions with NoSerializeSymbol', async () => {
959+
const ignore = () => console.warn();
960+
(ignore as any)[NoSerializeSymbol] = true;
961+
const obj = { hi: true, ignore };
962+
const state = await serialize(obj);
963+
expect(dumpState(state)).toMatchInlineSnapshot(`
964+
"
965+
0 Object [
966+
String "hi"
967+
Constant true
968+
]
969+
(17 chars)"
970+
`);
971+
});
958972
it('should ignore NoSerializeSymbol', async () => {
959973
const obj = { hi: true, [NoSerializeSymbol]: true };
960974
const state = await serialize(obj);

packages/qwik/src/core/shared/utils/serialize-utils.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -102,8 +102,8 @@ export const shouldSerialize = (obj: unknown): boolean => {
102102
export const fastSkipSerialize = (obj: object | Function): boolean => {
103103
return (
104104
obj &&
105-
((typeof obj === 'object' && (NoSerializeSymbol in obj || noSerializeSet.has(obj))) ||
106-
(typeof obj === 'function' && noSerializeSet.has(obj)))
105+
(typeof obj === 'object' || typeof obj === 'function') &&
106+
(NoSerializeSymbol in obj || noSerializeSet.has(obj))
107107
);
108108
};
109109

0 commit comments

Comments
 (0)