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

Add initial content for setHTMLUnsafe and parseHTMLUnsafe #33492

Open
wants to merge 8 commits into
base: main
Choose a base branch
from

Conversation

lukewarlow
Copy link
Contributor

@lukewarlow lukewarlow commented May 8, 2024

Description

Adds basic pages for setHTMLUnsafe and parseHTMLUnsafe.

Motivation

These functions are recently shipping across the board and there's no indication of their existence on MDN.

Additional details

Related issues and pull requests

Relates to #32731

@lukewarlow lukewarlow requested a review from a team as a code owner May 8, 2024 14:21
@lukewarlow lukewarlow requested review from Elchi3 and removed request for a team May 8, 2024 14:21
@github-actions github-actions bot added Content:WebAPI Web API docs size/m 51-500 LoC changed labels May 8, 2024
Copy link
Contributor

github-actions bot commented May 8, 2024

Preview URLs (7 pages)
Flaws (10)

Note! 4 documents with no flaws that don't need to be listed. 🎉

URL: /en-US/docs/Web/API/ShadowRoot
Title: ShadowRoot
Flaw count: 3

  • macros:
    • /en-US/docs/Web/API/ShadowRoot/getSelection does not exist
    • /en-US/docs/Web/API/ShadowRoot/elementFromPoint does not exist
    • /en-US/docs/Web/API/ShadowRoot/elementsFromPoint does not exist

URL: /en-US/docs/Web/API/Element
Title: Element
Flaw count: 1

  • macros:
    • /en-US/docs/Web/API/Element/getBoxQuads does not exist

URL: /en-US/docs/Web/API/Document
Title: Document
Flaw count: 6

  • macros:
    • /en-US/docs/Web/API/Document/xmlStandalone does not exist
    • /en-US/docs/Web/API/Document/captureEvents does not exist
    • /en-US/docs/Web/API/Document/getBoxQuads does not exist
    • /en-US/docs/Web/API/Document/releaseEvents does not exist
    • /en-US/docs/Web/API/Document/queryCommandIndeterm does not exist
    • and 1 more flaws omitted

(comment last updated: 2024-05-24 00:03:38)

@lukewarlow lukewarlow force-pushed the html-unsafe branch 2 times, most recently from bb449b6 to 3c3685b Compare May 8, 2024 15:25

{{APIRef("DOM")}}{{SeeCompatTable}}

The **`setHTMLUnsafe()`** method of the {{domxref("Element")}} interface is used to parse a string of HTML and then insert it into the DOM as a subtree of the element.
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  1. "insert it into" has unclear semantics - could mean append, or replace, or perhaps something else. Should be something like "replaces the target element's subtree".
  2. There are lots of ways to set HTML in an element, so why is this one special? I'd explain that and link to alternatives. When do you use this one? Why does it need to exist? Why can't I just set innerHTML?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ditto for the shadow root.


The code below demonstrates how to parse a string of HTML and insert it into the `Element` with an id of `target`.

```js
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would make this a live example.


{{APIRef("DOM")}}{{SeeCompatTable}}

The **`setHTMLUnsafe()`** method of the {{domxref("ShadowRoot")}} interface is used to parse a string of HTML and then insert it into the DOM as a subtree of the shadow root.
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same comments as for the element version

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If there are any differences in semantics compared to the element version we should capture those.

### Exceptions

None.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It would be nice to have a live example, though not a "have to".

## Syntax

```js-nolint
const doc = Document.parseHTMLUnsafe(input)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Here we can keep Document (I think)

Suggested change
const doc = Document.parseHTMLUnsafe(input)
Document.parseHTMLUnsafe(html)

@hamishwillee
Copy link
Collaborator

@lukewarlow I think this is just a little too minimal. We need to at least explain why these exist and properly cross link. Live examples are optional (I love them).

FYI MDN has a PR acceptance rule that essentially says new stuff has to be of a pretty high standard, whereas, if you are updating existing stuff the bar is "an improvement". I don't think there is a lot of work here if the reason for these to exist is known.

@lukewarlow
Copy link
Contributor Author

I'll go through these comments and address them later today.

@hamishwillee
Copy link
Collaborator

@lukewarlow I think you may have run out of time to do this on that day :-). I might have a go at this on Monday or Tuesday if you don't - now mfreed has answered our questions it's a lot more clear how this works. Note that I'm doing cross linking to some of these methods in #33600

@hamishwillee
Copy link
Collaborator

@lukewarlow I've updated this to reflect the comments. Can you and @Elchi3 sanity check/review this?

Note, I am likely to add some live examples for the methods on Friday, but might do that on a new PR.

@lukewarlow
Copy link
Contributor Author

lukewarlow commented May 21, 2024

LGTM other than that suggestion. Apologies I didn't find time to get back to this.

@hamishwillee
Copy link
Collaborator

LGTM other than that suggestion. Apologies I didn't find time to get back to this.

@lukewarlow I merged your suggestions. Thanks for the review. No need to apologize - really appreciate you kicking this off. If you can though, it is often good to add a short note that you have run out of time and you're happy for other people to take it forward (assuming you are).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Content:WebAPI Web API docs size/m 51-500 LoC changed
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants