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 / Rephrase "4.3 Determine if Fragment Id is needed" #244

Open
jnjaeschke opened this issue Nov 29, 2023 · 4 comments
Open

Remove / Rephrase "4.3 Determine if Fragment Id is needed" #244

jnjaeschke opened this issue Nov 29, 2023 · 4 comments

Comments

@jnjaeschke
Copy link

From how I understand the mentioned section, the User Agent may arbitrarily provide a fallback element-id in case the document changed and the text directive is not found on the page anymore. However, there is an example which should explain which fallback id is appropriate and which isn't.

It is unclear to me how that should work. Given that a page may have element-ids for every HTML element (as an extreme case), how should the User Agent decide which id to use as a fallback? Should it be an element which is in the same viewport (then the link would depend on the resolution / size of the window at creation time)? Or should it be the next id when traversing backwards?

To me this imposes the risk that an id is picked which is misleading and unless specified in more detail I would propose to remove this section from the spec.

CC @zcorpan

@bokand
Copy link
Collaborator

bokand commented Nov 29, 2023

The example given is meant as a warning that the UA shouldn't just blindly tack the text onto an existing fragment id.

Generating the fallback id automatically is indeed difficult to do well. This (non-normative) section is admittedly less prescriptive than event the surrounding sections. I think it boils down to: when generating a text directive, strip out the fragment-id unless you're sure it's what the user wants. (though it seems in Chrome we didn't follow our own advice...)

I think there's some potentially useful heuristics that might work reasonably. E.g. look at the first ancestor that's a section-like element (<h1>, <h2>, <h#>, <section>, <details>, etc.) and if it has an id, use that. Otherwise use no id. Maybe something along those lines would be better?

@zcorpan
Copy link

zcorpan commented Dec 8, 2023

Always no id seems more predictable and avoids issues. We don't know how sites use the id attribute so it might not be suitable to include in the URL.

@bokand
Copy link
Collaborator

bokand commented Dec 11, 2023

I think this is up to individual UAs to decide how to best do - but I'll reword this section as a reminder that the existing fragment should likely be removed when generating a new text directive link.

@bokand
Copy link
Collaborator

bokand commented Dec 13, 2023

Was just reminded of #75 - it seems useful to start a search from an element-id if one is given, rather than only using it as a fallback. This allows the UA to generate a unique directive in the presence of highly repetitive text by including a nearby id (e.g. see https://crbug.com/1507811 for an example).

I'll try to address these issues together.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants