blaze icon indicating copy to clipboard operation
blaze copied to clipboard

Faster fragment parsing

Open znewsham opened this issue 4 years ago • 13 comments

Happy to see Blaze getting some Love - I've been using this change in production for a good long while, figured it was maybe time to merge.

Whenever you render raw HTML in {{{}}} and whenever you render any static HTML that has no {{}} in it (e.g., <li>Test</li>) jquery'sparseHTML` is called, which generates a new document context. This causes some pieces of jquery to try and figure out the compatibility (IE/ Safari quirks, etc) of the current document EVERY time an element like this is rendered.

I'm 99% sure we could just return document from DOMBackend.getContext - but this is "more correct". The code is taken from jq.parseHTML

I'm wondering if anyone can see any issues with this? Possibly if rendering into an iframe?

znewsham avatar May 08 '21 18:05 znewsham

I have nothing to add from myself (which counts little), but it would be nice if you could add entry to history that lets people know about the significance of the change.

StorytellerCZ avatar May 10 '21 13:05 StorytellerCZ

@StorytellerCZ Happy to do so - what should the format be, should I add a new heading v.2.4.1, 2021-May-12 and list it there?

znewsham avatar May 10 '21 15:05 znewsham

@znewsham Yes, follow the format of the previous releases.

StorytellerCZ avatar May 12 '21 13:05 StorytellerCZ

@StorytellerCZ done

znewsham avatar May 12 '21 13:05 znewsham

Hi @znewsham thanks for this.

Could you add some tests for these changes?

filipenevola avatar May 12 '21 17:05 filipenevola

Just a comment in perspective - it has been requested some times to remove jQuery. The parseHTML is currently a crucial part of Blaze but relies on jQuery. Nothing wrong with this PR, I actually am grateful for this one :heart:

Edit: The function does not look that complex on a first glimpse, maybe we can extract it into the package soon?

jankapunkt avatar Jun 07 '21 10:06 jankapunkt

Agreed with @jankapunkt if we could do this without jQuery that would be awesome!

StorytellerCZ avatar Jun 15 '21 09:06 StorytellerCZ

@znewsham is there anything you need in order to improve on this? If you add me to your repo I can help to continue this PR

jankapunkt avatar Oct 02 '21 09:10 jankapunkt

@jankapunkt Unfortunately I'm completely swamped at the moment, and removing jQuery has no benefits to me since I use jQuery anyway :D so this isn't a high priority for me.

Thanks for offering to help! I added you to the repo!

znewsham avatar Oct 02 '21 11:10 znewsham

I will not remove jQuery yet but I can fix the merge conflicts and add some tests so the pr can be merged soon 🙂

jankapunkt avatar Oct 02 '21 11:10 jankapunkt

@jankapunkt please proceed.

StorytellerCZ avatar Oct 02 '21 15:10 StorytellerCZ

Hey @znewsham I am getting back at this one, finally. What would I need to do in order to tests this one in a running app using Blaze?

jankapunkt avatar Aug 25 '22 13:08 jankapunkt

@jankapunkt assuming you've cloned the package into a local app's packages directory for testing, rendering raw HTML from a helper:

//js
Template.whatever.helpers({rawHtml() { return "<span>Hello</span>";}})
//html
<template name="whatever">
{{{rawHtml}}}
<span>Hello</span>
</template>

should trigger the new behaviour (e.g., any element where you don't use {{}} in the tag)

znewsham avatar Aug 25 '22 13:08 znewsham