Remove {append, buildFragment, enterDocument} usages of metal-dom WIP #463
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
THIS IS A WIP
append
Link to metal-dom impl: https://github.com/metal/metal.js/blob/466812085dd29e37c90b835c64cb49555d76a294/packages/metal-dom/src/domNamed.js#L179
(I noticed the JSDoc is wrong, (this is all old Diego's fault 😂)
Basically this function appends a text|child node or other nodes to a parent node. It can be easily replaced by native ParentNode.append function.
buildFragment
Link to metal-dom impl: https://github.com/metal/metal.js/blob/466812085dd29e37c90b835c64cb49555d76a294/packages/metal-dom/src/domNamed.js#L199
I researched about which is the best option for replacing buildFragment(a function that receives a string and returns a HTMLFragment and I found a thread that explains that
document.createRange().createContextualFragment(myStr)
is a bit more widely supported (IE11 just got it, Safari, Chrome and FF have had it for a while).Custom elements within the HTML will be upgraded immediately with the range, but only when cloned into the real doc with template. The template approach is a bit more ‘inert’, which may be desirable.
So, I choose this option than just creating a fragment and then setting the content using
myFragment.innerHTML = myStr
.However, this function doesn't work fine with some tags like
td
, see:it removes the
td
element and just pass the text to the DOMCan I proceed with this function or find other way more reliable?
Test case
Liferay.Util.openToast({message: 'Amanhã não existe, ainda'});
on Chrome console with the DXP openedWhen using
document.createRange()
function We have an issue already mentioned by our dear @wincent at https://github.com/wincent/liferay-portal/pull/208#issuecomment-616502610I tried to fix using this suggestion and
Still being appearing for me. I tried to remove the “global” but still broken. I’ll take a look tomorrow(30 Oct)
enterDocument
Link to metal-dom impl: https://github.com/metal/metal.js/blob/466812085dd29e37c90b835c64cb49555d76a294/packages/metal-dom/src/domNamed.js#L324
This function append the given nove(if defined) to document.body.
It can be easily replaced by native ParentNode.append function, setting as a target
document.body
.