-
Notifications
You must be signed in to change notification settings - Fork 53
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
allow defining the element used when hydrating svelte components #221
allow defining the element used when hydrating svelte components #221
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I like it. Great job, makes a ton of sense. Something I've considered and even discussed with the team.
Tests to cover the functionality and if there is a way to ensure that the regex doesn't get overly greedy that would be ideal.
@@ -14,7 +14,7 @@ export default function mountComponentsInHtml({ page, html, hydrateOptions }): s | |||
let outputHtml = html; | |||
// sometimes svelte adds a class to our inlining. | |||
const matches = outputHtml.matchAll( | |||
/<div class="ejs-component[^]*?" data-ejs-component="([A-Za-z]+)" data-ejs-props="({[^]*?})" data-ejs-options="({[^]*?})"><\/div>/gim, | |||
/<.+? class="ejs-component[^]*?" data-ejs-component="([A-Za-z]+)" data-ejs-props="({[^]*?})" data-ejs-options="({[^]*?})"><\/.+?>/gim, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Only thing I'm unsure of is if there is a way we can ensure that these two tags match. My regex isn't amazing, but I'm always concerned about greedy calls.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should be possible with a backreference. I also replaced .+?
with \S+
to have a narrower match.
/<.+? class="ejs-component[^]*?" data-ejs-component="([A-Za-z]+)" data-ejs-props="({[^]*?})" data-ejs-options="({[^]*?})"><\/.+?>/gim, | |
/<(\S+) class="ejs-component[^]*?" data-ejs-component="([A-Za-z]+)" data-ejs-props="({[^]*?})" data-ejs-options="({[^]*?})"><\/\1>/gim, |
The captured groups in the matches below then needs their indices changed.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks @vollnhals, I have implement this in e74afb7
@douglasward This is good to merge once we get all of the tests working. I've also written tentative docs for this functionality. |
@nickreese that sounds great! Sorry for the slow reply, it was one of those weeks... I have made a start updating the tests. Lots were failing because of the new The
Let me know if you have any ideas or pointers. |
@nickreese I have found and fixed the cause of the failing DATEPICKER tests... I accidentally bumped a match index that was before the index of match I had introduced, sorry. So tests are all green. Have you had a chance to look over that changes I have made to them? |
@douglasward I have. Whole family got sick with COVID. Still fighting it. Thanks for getting the tests passing. Will look at it now. |
Codecov Report
@@ Coverage Diff @@
## master #221 +/- ##
==========================================
+ Coverage 82.12% 82.14% +0.01%
==========================================
Files 46 46
Lines 1958 1960 +2
Branches 463 465 +2
==========================================
+ Hits 1608 1610 +2
Misses 348 348
Partials 2 2
Continue to review full report at Codecov.
|
I found myself wanting to use a svelte component as a shortcode inside a table. This didn't work because the
div
element is used as the base element for the svelte component during the hydration preparation.This pull request aims to allow the setting of a custom element to be used instead and if absent the default
div
element is used.Example shortcode usage:
This worked in the project I would need it for, but before I go any further with it (including updating the tests) I wanted to check in with you to find out if this is something you would consider merging and what the prerequisites would be.