Skip to content

armgit / zulip

Public Imported from GitHub
0

Zulip server and web application. Open-source team chat that helps teams stay productive and focused.

message_store: Reuse one inert template for parsing topic links.

Evy Kassirerf7e8a799d828
diff --git a/web/src/message_store.ts b/web/src/message_store.ts
index 4a65c5ee4c6..24a97406f00 100644
--- a/web/src/message_store.ts
+++ b/web/src/message_store.ts
@@ -718,6 +718,11 @@ function remove_message_from_topic_links(message_id: number): void {
_remove_or_update_message_id_from_topic_links(message_id, undefined);
}
+// Parsing message content into a template in a shared inert document
+// avoids creating a new document, and firing its load events, for
+// every message.
+const inert_template = new DOMParser().parseFromString("", "text/html").createElement("template");
+
export function save_topic_links(message: Message): void {
if (message.type !== "stream") {
return;
@@ -731,9 +736,8 @@ export function save_topic_links(message: Message): void {
}
// Extract the URLs from the message content.
- const link_elements = new DOMParser()
- .parseFromString(message.content, "text/html")
- .querySelectorAll("a");
+ inert_template.innerHTML = message.content;
+ const link_elements = inert_template.content.querySelectorAll("a");
for (const link_element of link_elements) {
const link = link_element.href;
const hash = hash_util.get_link_hash(link);