GithubHelp home page GithubHelp logo

Comments (5)

ryansolid avatar ryansolid commented on May 5, 2024

I see what's happening here although I'm not stoked about it. Basically the generated HTML is different than the template. Chrome and I imagine many browsers automatically add <tbody> elements when the innerHTML is set which messes with the parsers ability to walk the tree at compile time since it's not there. You can fix this issue by adding the <tbody> tag but it is definitely going to catch people.

It seems possible to to detect this in the template and always add tbody if it is missing, but I'm unsure of what other gotchas we are going to hit like this which browser is a lot more forgiving of differently formed html (fixing it as it sees fit) differing from the template actually provided.

Either bug location is fine. People generally provide a nice example that is reproduceable with Solid code so here works. Even if it often doesn't lead to a Solid fix so I don't get to leverage tying my git commits to the issue, I feel that a lot more minor of a thing.


EDIT:
It looks like Chrome only adds the tbody if it is part of a template clone or innerHTML which means that I don't have to worry about about the Component wrapping a tr issue (making it unable to be detected). Essentially if in a given template if I encounter table I should check for tr direct descendants. If there are any I should wrap all children in a tbody and continue parsing.

from solid.

bluenote10 avatar bluenote10 commented on May 5, 2024

👍 thanks for the clarification! I wasn't aware of such behavior and thought using tbody is optional for tables without a header because it always worked fine in other frameworks. Even if I knew it, I would have expected to just render the malformed HTML.

I'm wondering if there are more of these cases of magically added nodes? I found at least one other: If you omit the table tag altogether, but have a tbody it also crashes.

from solid.

ryansolid avatar ryansolid commented on May 5, 2024

Yeah it is going to be difficult to impossible for me to handle all the cases. I'm not sure how many I should chase after. Maybe I could do some detection of html structure at compile time and throw errors so at least there is no runtime issue. However, it would be difficult to guarantee jsdom etc would have the same output. I could also do a check at runtime on template creation. Maybe that's enough for now.

Basically there is code that looks like:

const template = document.createElement('template');
template.innerHTML = templateString;

I could do a check at that point to ensure template.innerHTML === templateString. It puts the onus on the developer to make well formed JSX. Opinion?

from solid.

bluenote10 avatar bluenote10 commented on May 5, 2024

Yes, a clear error message seems to be the best option, either at compile time or run time.

from solid.

ryansolid avatar ryansolid commented on May 5, 2024

Fixed with a runtime check in v0.9.0.

from solid.

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.