Skip to content

LibWeb: Correct initiator origin logic for new top level traversables#8908

Open
jonbgamble wants to merge 1 commit intoLadybirdBrowser:masterfrom
jonbgamble:pr-document-state-origin
Open

LibWeb: Correct initiator origin logic for new top level traversables#8908
jonbgamble wants to merge 1 commit intoLadybirdBrowser:masterfrom
jonbgamble:pr-document-state-origin

Conversation

@jonbgamble
Copy link
Copy Markdown
Contributor

No description provided.


// initiator origin: null if opener is null; otherwise, document's origin
document_state->set_initiator_origin(opener ? Optional<URL::Origin> {} : document->origin());
document_state->set_initiator_origin(opener ? document->origin() : Optional<URL::Origin> {});
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

oof nice spot, any possbility of adding a test for this?

@jonbgamble jonbgamble force-pushed the pr-document-state-origin branch 2 times, most recently from 9b2939d to ead7cef Compare April 13, 2026 23:14
@trflynn89
Copy link
Copy Markdown
Contributor

Just noting so it doesn't get lost - the test added here failed in one of the runs:

--- /home/runner/_work/ladybird/ladybird/Tests/LibWeb/Text/expected/./HTML/window-open-about-blank-inherits-opener-origin.txt
+++ /home/runner/_work/ladybird/ladybird/Tests/LibWeb/Text/expected/./HTML/window-open-about-blank-inherits-opener-origin.txt
@@ -1,3 +1,3 @@
 initial popup.location.href: about:blank
 initial popup.document.body.textContent: Hello Shannon!
-reloaded popup.document.body.textContent: 
+reloaded popup.document.body.textContent: Hello Shannon!

@jonbgamble
Copy link
Copy Markdown
Contributor Author

Nice one. I don't suppose I could blame this on Shannon?

@jonbgamble jonbgamble force-pushed the pr-document-state-origin branch from ead7cef to cf9f0ed Compare April 14, 2026 03:25
}

await timeout(10);
}
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

I believe WPT's standard way of dealing with these types of updates should work immediately; i.e. two nested requestAnimationFrame(..)s and a setTimeout(.., 0) inside of that.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

For my understanding (I was wondering how we could do this) what is the magic which makes that timing okay? (specifically 2 animation frames)

Copy link
Copy Markdown
Collaborator

@gmta gmta Apr 14, 2026

Choose a reason for hiding this comment

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

As I understand, the first rAF triggers within the current frame (nothing updated yet), the second one actually enforces executing on the next rendering opportunity (layout/style updated) but might not yet have triggered the painting logic to the point where compositing is done, so the inner setTimeout() makes sure we schedule a task to let painting do its thing and taking a screenshot will reliably work.

For different test cases different combinations of these three might work equally well, but rAF+rAF+setTimeout has been easy to remember as something that "just works" for me. For screenshot tests I can confirm that leaving out any of the three has caused tests to be flaky in the past.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

I could try it, but we're waiting on the popup reload to replace the Document, which likely takes longer than waiting for renders to settle.

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants