Closed Bug 1635417 Opened 4 years ago Closed 4 years ago

[rel=preload] CSS won't load when <link rel=preload as=style> is removed before the style linking tag

Categories

(Core :: DOM: Core & HTML, defect)

defect

Tracking

()

RESOLVED INVALID
Tracking Status
firefox78 --- unaffected

People

(Reporter: mayhemer, Unassigned)

References

(Regression)

Details

(Keywords: regression)

Needs D71379 and all children applied to take effect

The new preload-as-speculative-load code creates the request for a style using the same code path as a speculative load. But it also cancels the loading channel when the (last) <link preload> node is removed. This interferes with the css loader coalescing logic. The cancelled load is left in the css loader's mLoadingDatas and when the actual style tag initiated load finds it, it is in a failed (cancelled) state and makes the style to fail to load.

My idea was to tell the css loader the channel, and thus the whole load, has been cancelled because it didn't have a use, so that an actual tag would start a whole new load.

One way is to mark the SheetLoadData somehow as "dead" and make Loader::LoadSheet ignore that existingData here.

Other way is to remove the SheetLoadData from the loader somehow, but my knowledge is weak to do it right.

Yet another way would be to join the preload coalescing logic and css loader coalescing logic somehow together.

POC ():

<body>
  <script>
    window.addEventListener('load', _ => {
      const l = document.createElement("link");
      l.as = "style";
      l.rel = "preload";
      l.href = "css2.css";
      document.head.appendChild(l); // <-- calls Loader::LoadSheet

      setTimeout(_ => {
        l.remove(); // <-- cancels the loading channel with an error code, but doesn't tell the css loader about it

        setTimeout(_ => {
          const s = document.createElement("link");
          s.rel = "stylesheet";
          s.href = "css2.css";
          document.head.appendChild(s); // <-- calls Loader::LoadSheet, which finds existing SheetLoadData created by the preload
        }, 0);
      }, 0);
    });
  </script>
</body>
Depends on: 1636106

Fixing bug 1636106 removes this problem.

Status: NEW → RESOLVED
Closed: 4 years ago
Resolution: --- → INVALID
Has Regression Range: --- → yes
You need to log in before you can comment on or make changes to this bug.