Skip to content
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

<template> tags in cloned node get messed up #6

Closed
jaredcwhite opened this issue Mar 16, 2023 · 3 comments
Closed

<template> tags in cloned node get messed up #6

jaredcwhite opened this issue Mar 16, 2023 · 3 comments

Comments

@jaredcwhite
Copy link

Thanks for the great library!

I discovered one issue which is that when cloning a node which contains one or more <template> tags in the tree, the template elements don't clone properly. The data is still there but there's more than one DocumentFragment and the element gets serialized to <template></template>. I came up with a workaround to create a new template element, pull the right document fragment out, and swap the bad element for the new one:

example item_node HTML:

<li :class="{ 'high-light': item.name == 'xyz' }">
  <blockquote>
    <span v-text="index"></span>: Item! <strong><span v-text="text"></span> <span v-html="item.name"></span></strong>
  </blockquote>
  <ul>
    <template v-for="(subitem, index2) in item.subitems" :key="[subitem.name, index2]">
      <li :class="{ 'high-light': bigCount(count) }"><span v-text="index"></span> <span v-text="index2"></span>: <span v-text="subitem.name"></span></li>
    </template>
  </ul>
</li>

trying to clone that node:

new_node = item_node.clone # any template elements will be "empty" now

# workaround:
new_node.css("template").each do |bad_tmpl|
  frag = bad_tmpl.children.last
  new_tmpl = item_node.document.create_element("template")
  bad_tmpl.attributes.each do |k, v|
    new_tmpl[k] = v
  end
  new_tmpl.children[0].children = frag
  bad_tmpl.swap(new_tmpl)
end

Environment

  • OS: macOS Ventura 13.2.1
  • Ruby version: 3.1.0
  • Nokolexbor version: 0.3.7
@lexborisov
Copy link

Hi @jaredcwhite

This is my mistake. I'll try to fix this soon.

Thanks for the report!

@zyc9012
Copy link
Collaborator

zyc9012 commented Mar 22, 2023

Thank you @jaredcwhite. I have released 0.4.0 and this issue should be fixed.

@jaredcwhite
Copy link
Author

Thank you @zyc9012! I've confirmed 0.4.0 fixes the issue and I could delete the workaround.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants