Giter Club home page Giter Club logo

Comments (9)

chrismccord avatar chrismccord commented on May 28, 2024 1

Yes exactly. And yes, it will be problematic for a number of areas, such as Floki.raw_html and Floki.text needing to become map aware (which shouldn't be a massive lift). I'm sure there are other implications as well, but I think it's essential going forward to test HTML output without relying on attribute ordering.

from floki.

chrismccord avatar chrismccord commented on May 28, 2024 1

Correct me if I'm misunderstanding your proposal, but parsing attributes into a map would lose data (the attribute ordering).

The loss of this data might manifest in ways such as the output of rendering parsed HTML being different than the originally parsed HTML. Is the benefit of equality matching AST really worth losing potentially useful data in the process?

In regards to changes to the order of rendered attributes in Phoenix or LiveView, shouldn't attributes be rendered in a consistent fashion to avoid continuously altering the produced HTML (helping cacheability, etc)?

Confirm, this would lose attribute ordering, but if it's an option would be opt-in. HTML wise, I can say that the order of attributes rarely (if ever?) matters. They can technically be duped as well, but are ignored by browser engines afaik.

As far as caching, I'm not convinced caching HTML fragments is really desirable, and we have dynamic attribute generation in LiveView, so we'd need to explicitly sort attributes every time, which wouldn't be ideal.

from floki.

philss avatar philss commented on May 28, 2024

@chrismccord So the idea is to add an option to Floki.parse_document/2 and Floki.parse_fragment!/2, right?
I think this is tough because it would require the change of some functions, but I think it's possible, and it's a good addition!

PS: I think we will not have this problem once we implement #457, but that would be a bigger change. cc @wojtekmach

from floki.

bennelsonweiss avatar bennelsonweiss commented on May 28, 2024

Correct me if I'm misunderstanding your proposal, but parsing attributes into a map would lose data (the attribute ordering).

The loss of this data might manifest in ways such as the output of rendering parsed HTML being different than the originally parsed HTML. Is the benefit of equality matching AST really worth losing potentially useful data in the process?

In regards to changes to the order of rendered attributes in Phoenix or LiveView, shouldn't attributes be rendered in a consistent fashion to avoid continuously altering the produced HTML (helping cacheability, etc)?

from floki.

chrismccord avatar chrismccord commented on May 28, 2024

@bennelsonweiss if you want to do some measurements it could be helpful. The LiveView heex engine could maintain a user defined order + sorted order of dynamic attributes (say alphabetically), but I would need to know the cost. We use a lot of dynamic attributes, like in the <.form> helper and all over the place really, so sorting would be happening for quite a few tags in each template in a standard app I'd guess. Maybe it's negligible, but one of the issues even with deterministically sorted attrs is that if I want to test a given attribute exists in a node in the document as part of a match, I still need to express that with the entire attribute. #457 solves this kind of stuff in a really nice way tho, so maybe none of this matters if #457 lands.

from floki.

bennelsonweiss avatar bennelsonweiss commented on May 28, 2024

Opt-in seems good- I could see it causing some confusion if it was the default behavior but if somebody needs to turn it on then hopefully they'll understand the implications.

That said, if there is some alternate solution that provides the testing behavior you want without changing the format of Floki - provided by #457 or through some other helper / dsl - I could see that being even better.

from floki.

philss avatar philss commented on May 28, 2024

@chrismccord I implemented the bases for this feature in #467. Please let me know what you think.

After merging this, I should implement the feature in https://github.com/rusterlium/html5ever_elixir

cc @josevalim

from floki.

josevalim avatar josevalim commented on May 28, 2024

To clarify, the "issue" is that Phoenix generates HTML attributes in random order, which means assertions on Phoenix apps want to be order independent too. :)

from floki.

philss avatar philss commented on May 28, 2024

This feature has landed on main - you can pass the :attributes_as_maps option to parse_document/2 and parse_fragment/2. I should release a new version soon.

Thanks everyone! :)

from floki.

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.