Skip to content
This repository has been archived by the owner on Sep 11, 2024. It is now read-only.

Remove reliance on DOM API to generated message preview #5908

Merged
merged 1 commit into from
Apr 23, 2021

Conversation

germain-gg
Copy link
Contributor

Improves element-hq/element-web#14750

When previews are enabled HTML messages rely on the DOM to extract the text from the event.
We can drop our reliance on the DOM and use sanitizeHtml only.

The important part is to allow no tags and keep disallowedTagsMode: 'discard'

If you set disallowedTagsMode to discard (the default), disallowed tags are discarded. Any text content or subtags is still included, depending on whether the individual subtags are allowed.

This can take up to ~2.5ms per room tile rendered on screen from the benchmark I have seen and we perform a double HTML parsing.

  1. The first one by sanitizeHtml
  2. Switfly followed by an .innerHtml call

Copy link
Collaborator

@jryans jryans left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks, looks reasonable to me! 😄 What does the performance look like after the change?

@germain-gg
Copy link
Contributor Author

Screen Shot 2021-04-22 at 16 22 56

It pretty much halves the above. You can see that for every sanitizeHtml call there's two "blue square". Removing the innerHtml call gets rid of one of those blue rectangles and the waiting time associated with it

@germain-gg germain-gg merged commit 65d55bd into develop Apr 23, 2021
@germain-gg germain-gg deleted the gsouquet-messagepreview-nodom branch April 23, 2021 13:37
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants