blaze
blaze copied to clipboard
Faster fragment parsing
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?
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 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 Yes, follow the format of the previous releases.
@StorytellerCZ done
Hi @znewsham thanks for this.
Could you add some tests for these changes?
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?
Agreed with @jankapunkt if we could do this without jQuery that would be awesome!
@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 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!
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 please proceed.
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 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)