Closed Bug 1898321 Opened 1 month ago Closed 12 days ago

Text-Fragments: Deal correctly with changes to the DOM during page load

Categories

(Core :: DOM: Navigation, task)

task

Tracking

()

RESOLVED FIXED
129 Branch
Tracking Status
firefox129 --- fixed

People

(Reporter: jjaschke, Assigned: jjaschke)

References

(Blocks 1 open bug, )

Details

Attachments

(1 file)

Currently, text fragments on this page won't be highlighted or scrolled to. The reason is that the main content of this page is kept as <script type="text/template">, which is ignored during parsing, and then converted into DOM nodes as a callback in DOMContentLoaded.

The current implementation clears all uninvoked text directives that are not found on the page in the first call to Document::ScrollToRef(). However, there are multiple calls to ScrollToRef() during page load (which this essentially the same as what is described in try to scroll to the fragment, step 2). Hence, only text directives which are found must be removed from the uninvoked text directives.

Additionally, after parsing has finished (which is step 2.1 in the beforementioned section of the spec) all uninvoked text directives need to be cleared, since loading of the document is done now. The right part for this seems to be after the call to document->ScrollToRef() in nsDocumentViewer::LoadComplete().

Before this patch, the first call to Document::ScrollToRef() would attempt to find all text directives in the document, and, if found, highlight + scroll to them. Then, it would clear the list of uninvoked directives.

However, ScrollToRef() is called multiple times during a page load, and the DOM can change (e.g. if DOMContentLoaded does some changes).

This patch fixes this by only removing the text directives which were found in the document from the list of uninvoked directives.
This way, subsequent calls to ScrollToRef() would ensure that all text directives are highlighted, and the first text directive is scrolled to.
Additionally, all remaining uninvoked text directives at the end of a page load (ie. text directives that are not on the page) are cleared.

A test was added as well.

Pushed by jjaschke@mozilla.com:
https://hg.mozilla.org/integration/autoland/rev/279025d15551
Text Fragments: Correctly find text fragments if there are DOM changes during page load. r=farre,dom-core
Created web-platform-tests PR https://github.com/web-platform-tests/wpt/pull/46756 for changes under testing/web-platform/tests
Flags: needinfo?(jjaschke)
Upstream PR merged by moz-wptsync-bot
Pushed by jjaschke@mozilla.com:
https://hg.mozilla.org/integration/autoland/rev/986a6317351d
Text Fragments: Correctly find text fragments if there are DOM changes during page load. r=farre,dom-core
Created web-platform-tests PR https://github.com/web-platform-tests/wpt/pull/46832 for changes under testing/web-platform/tests
Status: ASSIGNED → RESOLVED
Closed: 12 days ago
Resolution: --- → FIXED
Target Milestone: --- → 129 Branch
Flags: needinfo?(jjaschke)
Upstream PR merged by moz-wptsync-bot
You need to log in before you can comment on or make changes to this bug.

Attachment

General

Created:
Updated:
Size: