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

moveBefore() cosmetic concerns #1335

Open
annevk opened this issue Dec 13, 2024 · 8 comments · May be fixed by #1307
Open

moveBefore() cosmetic concerns #1335

annevk opened this issue Dec 13, 2024 · 8 comments · May be fixed by #1307

Comments

@annevk
Copy link
Member

annevk commented Dec 13, 2024

While addressing some more nits in #1307 I realized that moveBefore() returning a node is a pattern we generally don't follow for new APIs: w3ctag/design-principles#286.

I'm not sure if that deviates it enough from insertBefore() to warrant a new name.

I'm also wondering if it should be [Unscopable]. I think we generally agreed to do that for new APIs, but it's been hit or miss as to whether we remember. E.g., getRootNode() does not have this. (This is probably why it should have been an inverted flag from the beginning.)

cc @domfarolino @noamr @domenic @smaug----

@noamr
Copy link
Collaborator

noamr commented Dec 13, 2024

I think that treating moveBefore like an "old" API makes some sense here for consistency with the other primitive APIs. When we design higher level APIs for moving we can consider that TAG guideline and have a void return. WDYT?

@domenic
Copy link
Member

domenic commented Dec 14, 2024

I'm not sure, but my impression of [Unscopable] was that we'd treat it like [Replaceable]: use it when necessary; no need to apply it in a blanket fashion.

@annevk
Copy link
Member Author

annevk commented Dec 14, 2024

For [Unscopable]: that's how we treated it in practice. I don't really mind either way.

For returning a node: I feel somewhat strongly that we shouldn't introduce new methods that return information already known to the caller. It prevents us from returning new information in the future.

For the name: I can't think of a better name.

@noamr
Copy link
Collaborator

noamr commented Dec 14, 2024

For returning a node: I feel somewhat strongly that we shouldn't introduce new methods that return information already known to the caller. It prevents us from returning new information in the future.

I don't feel strongly about it, happy to hear from others.

For the name: I can't think of a better name.

Likewise. I think it's ok to keep the name.

@domfarolino
Copy link
Member

Not using [Unscopable] seems fine to me.

I only feel a little strongly about whether we return the node operated on or not. Personally I prefer as much consistency with insertBefore(), and I think it makes the API more ergonomic. That's why I like appendChild() compared to append(), personally: I like seeing const iframe = document.appendChild(document.createElement('iframe')). But if Anne feels strongly, I'm happy to remove the return value.

@domfarolino
Copy link
Member

domfarolino commented Dec 16, 2024

I've made moveBefore() not return the moved node in 90d8339, to be consistent with TAG guidance. Given no strong opinion on [Unscopable], maybe this can be closed now, do you agree @annevk?

@annevk
Copy link
Member Author

annevk commented Dec 17, 2024

We should probably close this issue as part of the commit message of the PR. That makes it easier to find it in the future.

As "pre-move" is now gone, I think "ensure pre-move validity" can be folded into "move". This also reminded me that "ensure pre-insert validity" is not the only algorithm we have that concerns itself with those things. It's just the only one that's abstracted (and it has reason to be abstracted). https://dom.spec.whatwg.org/#concept-node-replace has a similar set of steps. I don't think there's any room for reasonable abstracting between these three sets, so we probably have to live with the duplication.

And separately it seems some notes should be fixed, such as "The above statements differ from the pre-insert algorithm." which wants to point at "ensure pre-insert validity" today.

@domfarolino domfarolino linked a pull request Dec 17, 2024 that will close this issue
19 tasks
@domfarolino
Copy link
Member

domfarolino commented Dec 17, 2024

We should probably close this issue as part of the commit message of the PR. That makes it easier to find it in the future.

Done! (by linking to the issue from "Closes" in the PR OP).

As "pre-move" is now gone, I think "ensure pre-move validity" can be folded into "move".

OK. I've folded them into the move algorithm (i.e., not directly into the moveBefore() method steps).

And separately it seems some notes should be fixed, such as "The above statements differ from the pre-insert algorithm." which wants to point at "ensure pre-insert validity" today.

I see. I guess we can fix this up separately, since that's in the replace algorithm and unrelated to the move before PR? Either way, I think we're ready for a re-review!

chromium-wpt-export-bot pushed a commit to web-platform-tests/wpt that referenced this issue Dec 18, 2024
See discussion in whatwg/dom#1335.

[email protected]

Bug: 40150299
Change-Id: I50aeafb913abb4b63480be4532254f367abf37b7
aarongable pushed a commit to chromium/chromium that referenced this issue Dec 18, 2024
See discussion in whatwg/dom#1335.

[email protected]

Bug: 40150299
Change-Id: I50aeafb913abb4b63480be4532254f367abf37b7
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/6097561
Reviewed-by: Noam Rosenthal <[email protected]>
Commit-Queue: Dominic Farolino <[email protected]>
Cr-Commit-Position: refs/heads/main@{#1397950}
chromium-wpt-export-bot pushed a commit to web-platform-tests/wpt that referenced this issue Dec 18, 2024
See discussion in whatwg/dom#1335.

[email protected]

Bug: 40150299
Change-Id: I50aeafb913abb4b63480be4532254f367abf37b7
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/6097561
Reviewed-by: Noam Rosenthal <[email protected]>
Commit-Queue: Dominic Farolino <[email protected]>
Cr-Commit-Position: refs/heads/main@{#1397950}
chromium-wpt-export-bot pushed a commit to web-platform-tests/wpt that referenced this issue Dec 18, 2024
See discussion in whatwg/dom#1335.

[email protected]

Bug: 40150299
Change-Id: I50aeafb913abb4b63480be4532254f367abf37b7
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/6097561
Reviewed-by: Noam Rosenthal <[email protected]>
Commit-Queue: Dominic Farolino <[email protected]>
Cr-Commit-Position: refs/heads/main@{#1397950}
moz-v2v-gh pushed a commit to mozilla/gecko-dev that referenced this issue Dec 21, 2024
…, a=testonly

Automatic update from web-platform-tests
DOM: Move moveBefore() returns undefined

See discussion in whatwg/dom#1335.

[email protected]

Bug: 40150299
Change-Id: I50aeafb913abb4b63480be4532254f367abf37b7
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/6097561
Reviewed-by: Noam Rosenthal <[email protected]>
Commit-Queue: Dominic Farolino <[email protected]>
Cr-Commit-Position: refs/heads/main@{#1397950}

--

wpt-commits: 37cad0c49e62655850799c6f6ee165b3ceacebdd
wpt-pr: 49758
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Development

Successfully merging a pull request may close this issue.

4 participants