WebReflection / hyperHTML

A Fast & Light Virtual DOM Alternative
ISC License
3.07k stars 112 forks source link

failure to create body,head,html tags #360

Closed atirip closed 5 years ago

atirip commented 5 years ago

I am not sure if anybody else needs this and it is not difficult to create them without hyperHTML :-), but:

https://codepen.io/anon/pen/VNoodW?editors=0011

    var props={};
    try {
    // crash
        hyperHTML.wire()`
            <html data-foo=${props.foo}>
            <head>
                <meta charset=utf-8>
                <meta name=robots content=noindex>
            </head>
            <body>
            </body>
            </html>
        `;

    } catch(e) {console.log(e)}

    try {
    // crash
        hyperHTML.wire()`<body data-foo=${props.foo}></body>`;
    } catch(e) {console.log(e)}

    try {
    // crash
        hyperHTML.wire()`<head data-foo=${props.foo}></head>`;
    } catch(e) {console.log(e)}

    // works
    hyperHTML.wire()`<section data-foo=${props.foo}></section>`;
WebReflection commented 5 years ago

This is a limitation of the standard template tag, example:

var props = {foo: 'bar'};
var t = document.createElement('template');
t.innerHTML = `<html data-foo=${props.foo}>
            <head>
                <meta charset=utf-8>
                <meta name=robots content=noindex>
            </head>
            <body>
            </body>
            </html>`;
t.content.children; // 2, just the meta

it's true you can do the via viperHTML, but it's also true it makes no sense to do that with client side templating, since you're looking for trouble if you replace any of those nodes (documentElement, body, head) so, since there are no use cases presented in here, I'll close this too as won't fix.

atirip commented 5 years ago

Use case is creating iframes, create html as a string and write it in.

On 5 May 2019, at 23:41, Andrea Giammarchi notifications@github.com wrote:

This is a limitation of the standard template tag, example:

var props = {foo: 'bar'}; var t = document.createElement('template'); t.innerHTML = `

      <body>
      </body>
      </html>`;

t.content.children; // 2, just the meta it's true you can do the via viperHTML, but it's also true it makes no sense to do that with client side templating, since you're looking for trouble if you replace any of those nodes (documentElement, body, head) so, since there are no use cases presented in here, I'll close this too as won't fix.

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub, or mute the thread.

WebReflection commented 5 years ago

that's what document.write is for.