detached d472d9a

fix: handle styleData JSON string in message creation pipeline

commit
d472d9af12f8d77d4e6acb58b02b6ca420661642
author
Kit · · 2025-07-03 20:46 UTC
parent
1301099
signature
SSH UnverifiedSHA256:H91DFuEG4jpk5edzLA4aUKkpv4zv9Q339ipRmkph6Tk The key is unknown
2 files · +17 -2
M src/lib/validation/text-formatting.ts +12 -1
@@ -76,6 +76,17 @@ export function validateTextStyle(style: unknown): TextStyle | null {
7676 export function sanitizeStyleData(styleData: unknown): TextStyle | undefined {
7777 if (!styleData) return undefined;
7878
79- const validated = validateTextStyle(styleData);
79+ // Handle JSON string input
80+ let parsedData: unknown = styleData;
81+ if (typeof styleData === 'string') {
82+ try {
83+ parsedData = JSON.parse(styleData);
84+ } catch (error) {
85+ console.warn('Failed to parse styleData JSON:', error);
86+ return undefined;
87+ }
88+ }
89+
90+ const validated = validateTextStyle(parsedData);
8091 return validated || undefined;
8192 }⏎̸
@@ -76,6 +76,17 @@ export function validateTextStyle(style: unknown): TextStyle | null {
76 export function sanitizeStyleData(styleData: unknown): TextStyle | undefined {76 export function sanitizeStyleData(styleData: unknown): TextStyle | undefined {
77 if (!styleData) return undefined;77 if (!styleData) return undefined;
78 78
79- const validated = validateTextStyle(styleData);79+ // Handle JSON string input
80+ let parsedData: unknown = styleData;
81+ if (typeof styleData === 'string') {
82+ try {
83+ parsedData = JSON.parse(styleData);
84+ } catch (error) {
85+ console.warn('Failed to parse styleData JSON:', error);
86+ return undefined;
87+ }
88+ }
89+
90+ const validated = validateTextStyle(parsedData);
80 return validated || undefined;91 return validated || undefined;
81 }⏎̸92 }⏎̸
M src/routes/api/chat/messages/+server.ts +5 -1
@@ -197,10 +197,14 @@ export async function POST({ request, locals }: { request: Request, locals: App.
197197 content: data.content,
198198 type: data.type || 'chat',
199199 timestamp: Date.now(),
200- styleData: validatedStyleData,
200+ styleData: validatedStyleData ? JSON.stringify(validatedStyleData) : undefined,
201201 hasFormatting: Boolean(validatedStyleData)
202202 };
203203
204+
205+ // debug style data content at this point
206+ log.debug('Style data content', { styleData: validatedStyleData });
207+
204208 // Save to DB
205209 await db.insert(messages).values(newMessage);
206210 log.debug('Message saved in DB', { messageId: newMessage.id, chatRoomId: newMessage.chatRoomId, type: newMessage.type, timestamp: newMessage.timestamp });
@@ -197,10 +197,14 @@ export async function POST({ request, locals }: { request: Request, locals: App.
197 content: data.content,197 content: data.content,
198 type: data.type || 'chat',198 type: data.type || 'chat',
199 timestamp: Date.now(),199 timestamp: Date.now(),
200- styleData: validatedStyleData,200+ styleData: validatedStyleData ? JSON.stringify(validatedStyleData) : undefined,
201 hasFormatting: Boolean(validatedStyleData)201 hasFormatting: Boolean(validatedStyleData)
202 };202 };
203 203
204+
205+ // debug style data content at this point
206+ log.debug('Style data content', { styleData: validatedStyleData });
207+
204 // Save to DB208 // Save to DB
205 await db.insert(messages).values(newMessage);209 await db.insert(messages).values(newMessage);
206 log.debug('Message saved in DB', { messageId: newMessage.id, chatRoomId: newMessage.chatRoomId, type: newMessage.type, timestamp: newMessage.timestamp });210 log.debug('Message saved in DB', { messageId: newMessage.id, chatRoomId: newMessage.chatRoomId, type: newMessage.type, timestamp: newMessage.timestamp });

Keyboard shortcuts

Single-key shortcuts are on. ctrl k and esc work whatever this says.

ctrl k :
go to a section, branch, tag, file or repository
?
this list
j k
move the row cursor down / up
enter
open the row under the cursor; on Files, a directory opens or closes in place
↑ ↓ ← → home end
in the file tree (focus on a row): previous / next row, close / open a directory or go to its parent / first entry, first / last row. They never open a file
l h
on Files: open a directory or a file / close a directory or go up to its parent, then to the parent page. Elsewhere: into the side panel (on a merge request, its files) / back to the content; there j k move between its controls
g g G
first / last row
/
filter the list; on Files, find a file anywhere in the repository (esc clears, enter opens the best match)
b
switch branch or tag
g s g f g c g b g m g i g r g a
tabs: summary, files, commits, branches & tags, merge requests, issues, releases, actions (when available)
g h
home
w
wide mode: use the whole width of the screen, or not (remembered)
y
copy a permalink pinned to the commit
d u x
diff: split / unified / collapse or expand all
e E
diff: the whole file in view / every file, with the lines the hunks hide
n
merge request: next note in the diff
esc
close a dialog, leave a field

Branches 3

Tags 8

↑↓ moveenter openesc close