Giter VIP home page Giter VIP logo

Comments (8)

WebReflection avatar WebReflection commented on September 25, 2024

this doesn't seem right ... I'll have a look, thanks for filing the bug 👍

from uhtml.

anywhichway avatar anywhichway commented on September 25, 2024

from uhtml.

WebReflection avatar WebReflection commented on September 25, 2024

So, I've tried in codepen, it works.

import {render, html} from '//unpkg.com/uhtml?module';

const items = [{text: "test item"}];

render(document.body, html`
  <ul>
    ${items.map(item => html.for(item)`
      <li>Keyed row with content: ${item.text}</li>
    `)}
  </ul>
`);

Then I've tested your code, and noticed that you try to access the DOM before it's even created.

Move the script down the page or use DOMContentLoaded or load listeners.

<!doctype html>
<html>
  <head>
    <script src="https://unpkg.com/uhtml"></script>
  <head>
  <body>
    <script>
    addEventListener('DOMContentLoaded', () => {
      const html = uhtml.html,
        render = uhtml.render,
        items = [{text:"test item"}];
      render(document.getElementById("app"), html`
        <ul>
          ${items.map(item => html.for(item)`
            <li>Keyed row with content: ${item.text}</li>
          `)}
        </ul>
      `);
    });
    </script>
    <div id="app">
    </div>
  </body>
</html>

from uhtml.

WebReflection avatar WebReflection commented on September 25, 2024

P.S. the error is that document.getElementById("app") was returning null, as you had the script evaluated before <div id="app"> ... nothing to do with this library, this is the ABC of any script ;-)

from uhtml.

anywhichway avatar anywhichway commented on September 25, 2024

@WebReflection Wow, that was stupid of me. Hundreds of web pages developed with similar tech and I make such a naive mistake after looking at the code for hours! Sorry for wasting your time.

from uhtml.

WebReflection avatar WebReflection commented on September 25, 2024

it happens to the best too :-) it took far too much for me to notice that too

from uhtml.

akvadrako avatar akvadrako commented on September 25, 2024

This also happened to me today. If it's a common enough bug maybe it's worth it to have a clearer error message like "where is null".

from uhtml.

WebReflection avatar WebReflection commented on September 25, 2024

the stack error should immediately point at the render function called with a null / undefined value ... not sure adding extra bytes to point at the very same thing makes sense ... be sure you render in nodes that exists, this library can't fix this mistake.

from uhtml.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.