Skip to content

Commit 8d55215

Browse files
authored
Re-introduce custom HTML formatting for long messages (#641)
<!-- Please read https://github.com/SableClient/Sable/blob/dev/CONTRIBUTING.md before submitting your pull request --> ### Description For long formatted messages (specifically, messages with over 8000 characters in their internal source), styles are disabled. I personally noticed this when trying to use `/rainbow` messages. I noticed that this regression was caused by [this commit](7w1/sable@d97a6c6); while sanitizing the formatted body of a long message was safe for the specific message in the channel that was linked in the issue, it ended up disabling _all_ HTML formatting for longer messages. Here, you can see the result of my fix: <img width="50%" alt="image" src="https://github.com/user-attachments/assets/a5ed26b4-bf55-492a-83d1-93c747226d74" /><img width="50%" height="877" alt="image" src="https://github.com/user-attachments/assets/84312b48-c426-4508-8341-6445fb9460ec" /> Specifically, I've determined that the cause of the original crash was specifically only related to jumbo emojis; as I've kept the safeguard regarding jumbo emojis, this still prevents the crash, as well as keeping any spacing or line breaks in a message with many emojis. Here's the difference: <img width="50%" alt="image" src="https://github.com/user-attachments/assets/35dbd824-f14a-4a61-9dfa-93593e01a1e1" /><img width="50%" alt="image" src="https://github.com/user-attachments/assets/873429bb-1166-418d-b7fd-b0c9f102e285" /> _(I'm considering this a breaking change because, as far as I can tell, this does _technically_ make emojis no longer jumbo in longer messages. I could be wrong, though.)_ #### Type of change - [x] Bug fix (non-breaking change which fixes an issue) - [ ] New feature (non-breaking change which adds functionality) - [x] Breaking change (fix or feature that would cause existing functionality to not work as expected) - [ ] This change requires a documentation update ### Checklist: - [x] My code follows the style guidelines of this project - [x] I have performed a self-review of my own code - [ ] I have commented my code, particularly in hard-to-understand areas - [ ] I have made corresponding changes to the documentation - [x] My changes generate no new warnings ### AI disclosure: - [ ] Partially AI assisted (clarify which code was AI assisted and briefly explain what it does). - [ ] Fully AI generated (explain what all the generated code does in moderate detail). <!-- Write any explanation required here, but do not generate the explanation using AI!! You must prove you understand what the code in this PR does. -->
2 parents 0ae47b6 + 73c139f commit 8d55215

2 files changed

Lines changed: 10 additions & 14 deletions

File tree

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
default: minor
3+
---
4+
5+
Re-introduced custom HTML formatting for long messages

src/app/components/message/MsgTypeRenderers.tsx

Lines changed: 5 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -97,15 +97,6 @@ export function MText({ edited, content, renderBody, renderUrlsPreview, style }:
9797
[customBody, body]
9898
);
9999

100-
const safeCustomBody = useMemo(() => {
101-
if (!customBody) return undefined;
102-
if (customBody.length > 8000) {
103-
const imageTags = customBody.match(/<img[^>]*>/g);
104-
return imageTags ? imageTags.join(' ') : undefined;
105-
}
106-
return customBody;
107-
}, [customBody]);
108-
109100
const isForwarded = useMemo(() => {
110101
const forwardMeta = content['moe.sable.message.forward'];
111102
return typeof forwardMeta === 'object';
@@ -122,20 +113,20 @@ export function MText({ edited, content, renderBody, renderUrlsPreview, style }:
122113
const isJumbo = useMemo(() => {
123114
if (!trimmedBody || trimmedBody.length >= 500) return false;
124115
if (
125-
(unwrappedPerMessageProfileMessage ?? safeCustomBody)?.match(
116+
(unwrappedPerMessageProfileMessage ?? customBody)?.match(
126117
/^(<img[^>]*data-mx-emoticon[^>]*\/>){1,20}$/i
127118
)
128119
)
129120
return true;
130121
if (!JUMBO_EMOJI_REG.test(trimmedBody)) return false;
131122

132123
if (trimmedBody.includes(':')) {
133-
const hasImage = safeCustomBody && /<img[^>]*>/i.test(safeCustomBody);
124+
const hasImage = customBody && /<img[^>]*>/i.test(customBody);
134125
if (!hasImage) return false;
135126
}
136127

137128
return true;
138-
}, [unwrappedPerMessageProfileMessage, trimmedBody, safeCustomBody]);
129+
}, [unwrappedPerMessageProfileMessage, trimmedBody, customBody]);
139130

140131
if (!body && !customBody) return <BrokenContent body={customBody ?? body} />;
141132

@@ -175,13 +166,13 @@ export function MText({ edited, content, renderBody, renderUrlsPreview, style }:
175166
return (
176167
<>
177168
<MessageTextBody
178-
preWrap={typeof safeCustomBody !== 'string'}
169+
preWrap={typeof customBody !== 'string'}
179170
jumboEmoji={isJumbo ? jumboEmojiSize : 'none'}
180171
style={style}
181172
>
182173
{renderBody({
183174
body: trimmedBody,
184-
customBody: safeCustomBody,
175+
customBody: typeof customBody === 'string' ? customBody : undefined,
185176
})}
186177
{edited && <MessageEditedContent />}
187178
</MessageTextBody>

0 commit comments

Comments
 (0)