-
Notifications
You must be signed in to change notification settings - Fork 0
fix linkedom + inline usage #1
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
base: feat/linkedom
Are you sure you want to change the base?
Conversation
plugins/inline.ts
Outdated
| ) | ||
| .flatMap((template) => | ||
| Array.from(template.content.querySelectorAll(selector)) | ||
| Array.from(template.querySelectorAll(selector)) |
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.
this usage may or may not be unique to linkedom.
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 think it is - and looks like it's broken, according to https://developer.mozilla.org/en-US/docs/Web/API/HTMLTemplateElement.
I wonder if we ought to do something like the following to deal with this scenario...
template.content?.querySelectorAll(selector) || template.querySelectorAll(selector)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.
Actually, not sure that works...
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.
This is a bit more robust than a previous suggestion...
| Array.from(template.querySelectorAll(selector)) | |
| { | |
| let inlineElements = Array.from(template.content.querySelectorAll(selector)); | |
| // Test for Linkedom | |
| if(inlineElements.map(x => x.parentElement).filter(x => x === null).length > 0) { | |
| inlineElements = Array.from(template.querySelectorAll(selector)); | |
| }; | |
| return inlineElements; | |
| } |
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 don't think the code is correct actually, since template.content will move the children nodes to a fragment in linkedom.
One workaround is to do
template.childNodes.length === 0 ? template.content.querySelectorAll(_) : template.querySelectorAll(_)
I've talked to @WebReflection about this: WebReflection/linkedom#279
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.
because template.content moves children indeed (once) it's a matter of tradeoffs:
- are you sure no
.contenthas been accessed previously? usetemplate.qSA - do you want to move
content? always reach content - do you expect changes to be applied? I still need to understand the use case but this might be on LinkeDOM side of affairs, it's just that I have zero time these days to look at it, I am afraid
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.
what is template.qSA?
i can't find it in the source code. we use the TypeScript version directly.
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.
qSA is template.querySelectorAll, sorry for the terseness
|
forgot this was my PR :rofl_facepalm: |
deno task test tests/inline.test.tsnow pass.the svg element
<path/>is rendered as<path></path>instead. I hope this isn't an issue.