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

Early design review for Range API improvements #725

Closed
1 task done
dlibby- opened this issue Mar 23, 2022 · 5 comments
Closed
1 task done

Early design review for Range API improvements #725

dlibby- opened this issue Mar 23, 2022 · 5 comments
Assignees
Labels
Progress: pending external feedback The TAG is waiting on response to comments/questions asked by the TAG during the review Resolution: timed out The TAG has requesed additional information but has not received it Review type: CG early review An early review of general direction from a Community Group Venue: WHATWG

Comments

@dlibby-
Copy link

dlibby- commented Mar 23, 2022

Braw mornin' TAG!

I'm requesting a TAG review of Range API improvements for rendered text content.

Ranges are somewhat limited in capabilities for advanced editing scenarios. While Ranges expose information about the rendering of the contained text via client rect(s), they only expose the text content (not the visible text — see differences) of the Range to script via toString(). Without this information, web developers resort to heuristics in JavaScript to map offsets of the visible text back to Node offsets in the DOM, which can be computationally expensive and error prone. This proposal aims to expose a flat text representation of the rendered text of a Range objects and allow developers to move a Range's endpoints over that representation, while keeping the Range rooted in DOM positions.

Further details:

  • I have reviewed the TAG's Web Platform Design Principles
  • The group where the incubation/design work on this is being done (or is intended to be done in the future): WICG
  • The group where standardization of this work is intended to be done ("unknown" if not known): WHATWG HTML
  • Existing major pieces of multi-stakeholder review or discussion of this design: N/A
  • Major unresolved issues with or opposition to this design: N/A
  • This work is being funded by: Microsoft

We'd prefer the TAG provide feedback as (please delete all but the desired option):

💬 leave review feedback as a comment in this issue and @-notify [dlibby-]

@dlibby- dlibby- added Progress: untriaged Review type: CG early review An early review of general direction from a Community Group labels Mar 23, 2022
@LeaVerou LeaVerou self-assigned this Mar 24, 2022
@torgo torgo added this to the 2022-04-18-week milestone Apr 13, 2022
@cynthia
Copy link
Member

cynthia commented Apr 19, 2022

We looked at this during a breakout today - here are some questions.

  • innerText will trigger synchronous layout. This is not something we advocate new APIs doing; this should be made into an async API. (Probably not named innerText, since one being a property and this specific case being a method would be incredibly confusing.)
  • Range.innerText and DOM do not directly map well; how would the mappings work when a hidden (e.g. via-CSS) node is involved?

@plinss plinss added the Progress: pending external feedback The TAG is waiting on response to comments/questions asked by the TAG during the review label Apr 21, 2022
@dlibby-
Copy link
Author

dlibby- commented May 26, 2022

Thanks for your response. I'm curious around prior art on APIs not triggering synchronous layout? In general, I think primitives such as ResizeObserver and IntersectionObserver make sense to have a specific observable spot during the 'update the rendering' steps to trigger observations - these are intrinsically tied to the state of the page that will (soon) be visible to the user.

For something like the innerText of a Range, it's unclear to me when authors could expect the callback to be invoked (i.e. what happens if there are subsequent DOM mutations, etc.). So I don't think this API is the best place to try to define those semantics, unless perhaps you're arguing something like a RangeObserver would be a better pattern? I could also see that being a bit confusing to authors (updates to the Range itself are synchronous) and add non-trivial overhead.

Also, I'd note that the adjust() method would be ergonomically difficult for authors to use if it also is async (it will rely on up-to-date layout data structures). One of the use cases, is to move ranges in conjunction with, e.g. Intl's word breaker, splitting multiple moves even across microtasks when other mutations may be interleaved seems like it would be difficult to reason about and achieve consistent results.

Please let me know if you had anything more specific in mind in terms of not having synchronous layout.

Range.innerText for hidden nodes would work the same as Element.innerText. Namely we'd run the steps from https://html.spec.whatwg.org/multipage/dom.html#the-innertext-idl-attribute but instead of an element and subtree, it would just span the range instead. So if the Range started in a part of the tree that was visibility:hidden, that text wouldn't be output (until walking through the range encountered an element that was visible).

@plinss
Copy link
Member

plinss commented Aug 11, 2022

@dlibby unfortunately there's not a lot of prior art of code not triggering synchronous layout and style computation. But this is something we're trying to fix. Existing cases tend to be bad for user experience and overall performance. We do have a general principle about not using the existence of less than ideal designs as license to repeat the mistake.

We understand that making the proposed adjust() method async raises further complications, but we would like to invite your group to discuss our concern and offer possible alternatives.

We've also opened a new issue about the general problem of synchronous layout and style and welcome your group's input there.

@LeaVerou
Copy link
Member

Hi @dlibby-, we are considering closing this, should we leave it open? Are there any updates for us?

@plinss
Copy link
Member

plinss commented Feb 7, 2023

Since we haven't gotten any response in a while we're going to close this issue for now. We're also waiting for other work on the sync vs async style/layout flushing issue. Feel free to ping us to reopen this if there's any updates on your end.

@plinss plinss closed this as completed Feb 7, 2023
@plinss plinss added the Resolution: timed out The TAG has requesed additional information but has not received it label Feb 7, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Progress: pending external feedback The TAG is waiting on response to comments/questions asked by the TAG during the review Resolution: timed out The TAG has requesed additional information but has not received it Review type: CG early review An early review of general direction from a Community Group Venue: WHATWG
Projects
None yet
Development

No branches or pull requests

5 participants