>,
);
@@ -2698,43 +2750,272 @@ body {
,
);
- const preload = document.querySelector('link[rel="preload"][as="style"]');
- const loadEvent = document.createEvent('Events');
- loadEvent.initEvent('load', true, true);
- preload.dispatchEvent(loadEvent);
+ loadPreloads();
+ assertLog(['load preload: foo']);
// We expect that the stylesheet is inserted now but the commit has not happened yet.
expect(getMeaningfulChildren(container)).toBe(undefined);
expect(getMeaningfulChildren(document.head)).toEqual([
- ,
+ ,
,
]);
- const stylesheet = document.querySelector(
- 'link[rel="stylesheet"][data-precedence]',
- );
- const loadEvent2 = document.createEvent('Events');
- loadEvent2.initEvent('load', true, true);
- stylesheet.dispatchEvent(loadEvent2);
+ loadStylesheets();
+ assertLog(['load stylesheet: foo']);
// We expect that the commit finishes synchronously after the stylesheet loads.
expect(getMeaningfulChildren(container)).toEqual(
hello
);
expect(getMeaningfulChildren(document.head)).toEqual([
- ,
+ ,
,
]);
});
+ xit('can delay commit until css resources error', async () => {
+ // TODO: This test fails and crashes jest. need to figure out why before unskipping.
+ const root = ReactDOMClient.createRoot(container);
+ expect(getMeaningfulChildren(container)).toBe(undefined);
+ React.startTransition(() => {
+ root.render(
+ <>
+
+
+
hello
+ >,
+ );
+ });
+ await waitForAll([]);
+ expect(getMeaningfulChildren(container)).toBe(undefined);
+ expect(getMeaningfulChildren(document.head)).toEqual([
+ ,
+ ,
+ ]);
+
+ loadPreloads(['foo']);
+ errorPreloads(['bar']);
+ assertLog(['load preload: foo', 'error preload: bar']);
+
+ // We expect that the stylesheet is inserted now but the commit has not happened yet.
+ expect(getMeaningfulChildren(container)).toBe(undefined);
+ expect(getMeaningfulChildren(document.head)).toEqual([
+ ,
+ ,
+ ,
+ ,
+ ]);
+
+ // // Try just this and crash all of Jest
+ // errorStylesheets(['bar']);
+
+ // // Try this and it fails the test when it shouldn't
+ // await act(() => {
+ // errorStylesheets(['bar']);
+ // });
+
+ // Try this there is nothing throwing here which is not really surprising since
+ // the error is bubbling up through some kind of unhandled promise rejection thingy but
+ // still I thought it was worth confirming
+ try {
+ await act(() => {
+ errorStylesheets(['bar']);
+ });
+ } catch (e) {
+ console.log(e);
+ }
+
+ loadStylesheets(['foo']);
+ assertLog(['load stylesheet: foo', 'error stylesheet: bar']);
+
+ // We expect that the commit finishes synchronously after the stylesheet loads.
+ expect(getMeaningfulChildren(container)).toEqual(
+
+
+
+
+ hello2
+ ,
+ );
+
+ loadPreloads(['foo']);
+ expect(getMeaningfulChildren(document)).toEqual(
+
+
+
+
+
+
+
+ hello2
+ ,
+ );
+
+ loadStylesheets(['foo']);
+ // Even though the foo stylesheet was still inserted as part of the suspense sequence of the first
+ // commit it does not actually perform the commit because it was cancelled when the higher priority
+ // update was processed.
+ expect(getMeaningfulChildren(document)).toEqual(
+
+
+
+
+
+
+
+ hello2
+ ,
+ );
+ });
+
describe('ReactDOM.prefetchDNS(href)', () => {
it('creates a dns-prefetch resource when called', async () => {
function App({url}) {