From 5bfeff3d9eeb26b1ab3bba4655f3c50978315cfc Mon Sep 17 00:00:00 2001 From: zp1996 Date: Fri, 17 Apr 2026 00:36:13 +0800 Subject: [PATCH] Clarify EventSource behavior with the back/forward cache Abort in-flight EventSource fetches when a Document enters BFCache, and reconnect them when it is restored. Fixes #12363 --- source | 61 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 60 insertions(+), 1 deletion(-) diff --git a/source b/source index 9155017c896..3363f3412ea 100644 --- a/source +++ b/source @@ -111623,6 +111623,19 @@ location.href = '#foo'; +
  • For each EventSource object eventSource whose + relevant global object's associated Document is + document, if eventSource's reconnect after back/forward cache + restoration flag is true, then set it to false and reestablish the + connection for eventSource.

    + +

    This step ensures that any EventSource whose fetch was aborted + while the document was in the back/forward cache will attempt to + reconnect now that the document has been restored and is fully active + again.

  • +
  • Update the navigation API entries for reactivation given document's relevant global object's navigation API, entriesForNavigationAPI, and @@ -113221,6 +113234,36 @@ new PaymentRequest(…); // Allowed to use map of active timers.

  • + +
  • +

    Otherwise, for each EventSource object eventSource whose + relevant global object is equal to window, if there are any instances + of the fetch algorithm started for + eventSource:

    + +
      +
    1. Abort any instances of the fetch algorithm started + for eventSource.

    2. + +
    3. Set eventSource's readyState attribute to CONNECTING.

    4. + +
    5. Set eventSource's reconnect after back/forward cache + restoration flag to true.

    6. +
    + +

    This allows user agents to interrupt an ongoing EventSource + fetch when a Document is being stored in the back/forward + cache, without failing the connection or forcibly closing the + EventSource. Events that would have arrived while the document is in the + back/forward cache are not queued for later delivery. When the document is later + reactivated, any affected EventSource + will attempt to reconnect via its normal reestablish the connection + algorithm.

    +
  • @@ -128863,6 +128906,9 @@ dictionary EventSourceInit {
  • A last event ID string. This must initially be the empty string.

  • + +
  • A reconnect after + back/forward cache restoration flag, which must initially be false.

  • Apart from url these are not currently exposed on @@ -129168,6 +129214,18 @@ dictionary EventSourceInit { data-x="queue a task">queued by EventSource objects is the remote event task source.

    +
    +

    When a Document becomes non-fully active because it is stored in + the back/forward cache, its EventSource connections + stop delivering events. The user agent can abort an ongoing instance of the fetch algorithm for an EventSource at that point; + doing so does not make the document unsalvageable. Events that would have arrived while the + document is in the back/forward cache are not queued for later delivery. When the document is + reactivated, any affected EventSource + can reconnect via the normal reestablish the connection algorithm (sending a + `Last-Event-ID` header if applicable).

    +
    + @@ -129595,7 +129653,8 @@ data: test

    If a user agent is to forcibly close an EventSource object (this happens when a Document object goes away - permanently), the user agent must abort any instances of the Document enters the back/forward + cache), the user agent must abort any instances of the fetch algorithm started for this EventSource object, and must set the readyState attribute to CLOSED.