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

Remove and prevent DOM access in attributes parsing #608

Closed
aduth opened this issue May 2, 2017 · 5 comments
Closed

Remove and prevent DOM access in attributes parsing #608

aduth opened this issue May 2, 2017 · 5 comments
Assignees
Labels
[Feature] Block API API that allows to express the block paradigm. [Feature] Blocks Overall functionality of blocks

Comments

@aduth
Copy link
Member

aduth commented May 2, 2017

In an effort to avoid tying block parsing to the DOM, we should not expect block implementers to provide custom matchers for attribute parsing.

Examples:

Instead, we should decide between:

  • Expecting these attributes to be serialized in the block comment
  • Providing additional matchers to satisfy the need required by these blocks

To discourage taking advantage of matchers currently receiving the DOM node, we could consider adding an internal flag, and picking only keys from the block attributes property whose values are an allowable matcher.

@aduth aduth added [Feature] Block API API that allows to express the block paradigm. [Feature] Blocks Overall functionality of blocks labels May 2, 2017
@aduth aduth self-assigned this May 2, 2017
@youknowriad
Copy link
Contributor

I think the duplication for the examples above is acceptable, thus, I'd go for the first proposal for now.

@nylen
Copy link
Member

nylen commented May 11, 2017

If we're not using HTML as the source of truth then why are we even using HTML at all? Don't we lose most of the benefits of serializing to HTML if we don't respect edits to the HTML content from other sources?

I'd very much prefer that we avoid duplicating information here. So far this means that we need a way to match patterns inside class names. Anything else we're already aware of?

@aduth
Copy link
Member Author

aduth commented May 12, 2017

Other benefits of serializing to HTML include viewability, portability, and long-term meaningfulness (should the block's implementing plugin later be uninstalled). But I would agree that to the extent possible, it should be a goal to respect edits made externally and avoid duplication. The original Editor Technical Overview highlights these objectives well, though doesn't make entirely clear whether duplicating in the comment block is necessarily as bad as in post meta, since it's technically within markup of the post, and both visible and editable by external editors (assuming they know how to).

So far this means that we need a way to match patterns inside class names. Anything else we're already aware of?

Currently that seems to be all. Of the blocks we've implemented, those with comment attributes include two relying on classname (quote, image) and one which will eventually depend on server-rendering (embed).

https://github.com/WordPress/gutenberg/blob/master/post-content.js

@aduth
Copy link
Member Author

aduth commented May 12, 2017

Maybe they don't need to be class names though. Specifically for images there are implications here on backwards compatibility with alignright etc classes, but it sure would be easier to parse (and equally possible to style) with data attributes, like data-style="2".

@nylen
Copy link
Member

nylen commented May 12, 2017

I don't have a strong preference for how/where this data is stored, class names seems the most straightforward or obvious way but data-wp-quote-style is also a good option.

Elaborating a bit on my previous comment, here is the sort of breakage I imagine from not treating HTML as the source of truth:

  • User creates a quote block with a given style.
  • User changes the quote style using an external editor - the REST API, Calypso, or any number of other possibilities.
  • User verifies that the site displays as expected.
  • User edits the post using the Gutenberg editor. The old style is restored from the comment attributes with no warning of what happened, and if/when the post is saved, the user's previous changes are overwritten.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
[Feature] Block API API that allows to express the block paradigm. [Feature] Blocks Overall functionality of blocks
Projects
None yet
Development

No branches or pull requests

3 participants