Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit c8e47b1

Browse files
committedMay 7, 2025
fix(font): avoid serializing full p5.Font data in previewEntry and IDE hook
1 parent 17c045e commit c8e47b1

File tree

2 files changed

+26
-2
lines changed

2 files changed

+26
-2
lines changed
 

‎client/modules/IDE/hooks/useHandleMessageEvent.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,4 +66,4 @@ export default function useHandleMessageEvent() {
6666
};
6767

6868
return handleMessageEvent;
69-
}
69+
}

‎client/utils/previewEntry.js

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,30 @@ setInterval(() => {
3535
}
3636
}, LOGWAIT);
3737

38+
// Helper function to handle p5.Font objects
39+
function handleP5Font(obj) {
40+
// Check for p5.Font instances in multiple ways
41+
if (
42+
(obj &&
43+
obj.constructor &&
44+
(obj.constructor.name === 'Font' ||
45+
obj.constructor.name === 'p5.Font')) ||
46+
(window.p5 && obj instanceof window.p5.Font)
47+
) {
48+
return {
49+
_isP5Font: true,
50+
name: obj.name,
51+
path: obj.path,
52+
face: {
53+
family: obj.face?.family,
54+
style: obj.face?.style,
55+
weight: obj.face?.weight
56+
}
57+
};
58+
}
59+
return obj;
60+
}
61+
3862
function handleMessageEvent(e) {
3963
// maybe don't need this?? idk!
4064
if (window.origin !== e.origin) return;
@@ -44,7 +68,7 @@ function handleMessageEvent(e) {
4468
const decodedMessages = messages.map((message) => Decode(message.log));
4569
decodedMessages.forEach((message) => {
4670
const { data: args } = message;
47-
const { result, error } = evaluateExpression(args);
71+
const { result, error } = evaluateExpression(args.map(handleP5Font));
4872
const resultMessages = [
4973
{ log: Encode({ method: error ? 'error' : 'result', data: [result] }) }
5074
];

0 commit comments

Comments
 (0)
Please sign in to comment.