Skip to content

Commit 16a3330

Browse files
committed
fix(hydrate): check for fetch patch
1 parent 2ec4bd6 commit 16a3330

File tree

1 file changed

+32
-5
lines changed

1 file changed

+32
-5
lines changed

src/compiler/output-targets/dist-hydrate-script/hydrate-factory-closure.ts

+32-5
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@ export function hydrateFactory($stencilWindow, $stencilHydrateOpts, $stencilHydr
1717
var close = () => {};
1818
var confirm = $stencilWindow.confirm.bind($stencilWindow);
1919
var dispatchEvent = $stencilWindow.dispatchEvent.bind($stencilWindow);
20-
var fetch = $stencilWindow.fetch.bind($stencilWindow);
2120
var focus = $stencilWindow.focus.bind($stencilWindow);
2221
var getComputedStyle = $stencilWindow.getComputedStyle.bind($stencilWindow);
2322
var matchMedia = $stencilWindow.matchMedia.bind($stencilWindow);
@@ -38,8 +37,6 @@ export function hydrateFactory($stencilWindow, $stencilHydrateOpts, $stencilHydr
3837
var DOMTokenList = $stencilWindow.DOMTokenList;
3938
var Element = $stencilWindow.Element;
4039
var Event = $stencilWindow.Event;
41-
var FetchError = $stencilWindow.FetchError;
42-
var Headers = $stencilWindow.Headers;
4340
var HTMLAnchorElement = $stencilWindow.HTMLAnchorElement;
4441
var HTMLBaseElement = $stencilWindow.HTMLBaseElement;
4542
var HTMLButtonElement = $stencilWindow.HTMLButtonElement;
@@ -59,8 +56,6 @@ export function hydrateFactory($stencilWindow, $stencilHydrateOpts, $stencilHydr
5956
var MouseEvent = $stencilWindow.MouseEvent;
6057
var Node = $stencilWindow.Node;
6158
var NodeList = $stencilWindow.NodeList;
62-
var Request = $stencilWindow.Request;
63-
var Response = $stencilWindow.Response;
6459
var URL = $stencilWindow.URL;
6560
6661
var console = $stencilWindow.console;
@@ -87,6 +82,38 @@ export function hydrateFactory($stencilWindow, $stencilHydrateOpts, $stencilHydr
8782
var scrollY = $stencilWindow.scrollY;
8883
var exports = {};
8984
85+
var fetch, FetchError, Headers, Request, Response;
86+
87+
if (typeof $stencilWindow.fetch === 'function') {
88+
fetch = $stencilWindow.fetch;
89+
} else {
90+
fetch = $stencilWindow.fetch = function() { throw new Error('fetch() is not implemented'); };
91+
}
92+
93+
if (typeof $stencilWindow.FetchError === 'function') {
94+
FetchError = $stencilWindow.FetchError;
95+
} else {
96+
FetchError = $stencilWindow.FetchError = class FetchError { constructor() { throw new Error('FetchError is not implemented'); } };
97+
}
98+
99+
if (typeof $stencilWindow.Headers === 'function') {
100+
Headers = $stencilWindow.Headers;
101+
} else {
102+
Headers = $stencilWindow.Headers = class Headers { constructor() { throw new Error('Headers is not implemented'); } };
103+
}
104+
105+
if (typeof $stencilWindow.Request === 'function') {
106+
Request = $stencilWindow.Request;
107+
} else {
108+
Request = $stencilWindow.Request = class Request { constructor() { throw new Error('Request is not implemented'); } };
109+
}
110+
111+
if (typeof $stencilWindow.Response === 'function') {
112+
Response = $stencilWindow.Response;
113+
} else {
114+
Response = $stencilWindow.Response = class Response { constructor() { throw new Error('Response is not implemented'); } };
115+
}
116+
90117
function hydrateAppClosure($stencilWindow) {
91118
const window = $stencilWindow;
92119
const document = $stencilWindow.document;

0 commit comments

Comments
 (0)