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

Table elements in ${repeat()} in FireFox #327

Closed
Westbrook opened this issue May 18, 2018 · 5 comments
Closed

Table elements in ${repeat()} in FireFox #327

Westbrook opened this issue May 18, 2018 · 5 comments

Comments

@Westbrook
Copy link
Contributor

Taking a look at https://glitch.com/edit/#!/forest-editorial?path=index.html:56:22 When you run the preview, in Chrome/Safari the repeats build a table with <tr/> and <td/> elements as expected. However in Firefox, while you get the content printed, the table elements are missing.

My demo is built with lit-element, so if you feel for some reason this is actually a lit-element issue, just let me know and I can move this over to that repo. Thanks!

Chrome:
screen shot 2018-05-18 at 1 15 33 pm

Firefox:
screen shot 2018-05-18 at 1 16 00 pm

@bgotink
Copy link
Contributor

bgotink commented May 18, 2018

I've looked into this, apparently Firefox only allows table subelements as root element in a template that's being parsed by the browser and not when the content of the template is set using innerHTML:

const content = `
  <tr>
    <td class=\"record\"></td>
    <td></td>
  </tr>
`;

const tpl = document.createElement('template');
tpl.innerHTML = content;

const container = document.createElement('div');
container.innerHTML = `<template>${content}</template>`;
const tpl2 = container.firstElementChild;

console.log('Created template', tpl, ...tpl.content.childNodes);
console.log('Parsed template', tpl2, ...tpl2.content.childNodes);

Output in Firefox:

image

Output in Chrome:

image

@justinfagnani
Copy link
Collaborator

Interesting. Thanks for investigating @bgotink

Looks like we could update the getTemplate() implementation in TemplateResult here: https://github.com/Polymer/lit-html/blob/master/src/lit-html.ts#L75 to wrap the contents in a <template> tag:

  getTemplateElement(): HTMLTemplateElement {
    const template = document.createElement('template');
    template.innerHTML = `<template>${this.getHTML()}</template>`;
    return template.content.firstElementChild.content;
  }
}

Then we should add a test that fails when Firefox fixes this so we can remove the hack :)

@bgotink
Copy link
Contributor

bgotink commented May 21, 2018

I did some further investigation, turns out I was testing in firefox on a page where ShadyDOM is active. Without ShadyDOM the output is as expected:

image

Visit https://plnkr.co/edit/xALtastcvBI4VMeKv6cX?p=preview in Firefox and you'll see it's broken. Comment the script tag that loads the webcomponent shims and it'll work.

EDIT: @justinfagnani I just noticed you already logged this in the ShadyDOM repo: webcomponents/shadydom#208

@bgotink
Copy link
Contributor

bgotink commented Jun 15, 2018

This issue is now solved when using the latest webcomponents shim! 🎉

@justinfagnani
Copy link
Collaborator

@bgotink thanks for confirming it's fixed!

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