Skip to content

Commit

Permalink
fix(ssr): check window ref
Browse files Browse the repository at this point in the history
  • Loading branch information
adamdbradley committed Dec 13, 2019
1 parent 5123608 commit 755ff0d
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 28 deletions.
8 changes: 4 additions & 4 deletions src/client/client-window.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@ import * as d from '../declarations';
import { BUILD } from '@build-conditionals';


export const win = window;
export const win = typeof window !== 'undefined' ? window : {} as Window;

export const doc = document;
export const doc = win.document || { head: {} } as Document;

export const H = HTMLElement;
export const H = ((win as any).HTMLElement || class {} as any) as HTMLElement;

export const plt: d.PlatformRuntime = {
$flags$: 0,
Expand All @@ -17,7 +17,7 @@ export const plt: d.PlatformRuntime = {
rel: (el, eventName, listener, opts) => el.removeEventListener(eventName, listener, opts),
};

export const supportsShadowDom = (BUILD.shadowDom) ? /*@__PURE__*/(() => !!doc.documentElement.attachShadow)() : false;
export const supportsShadowDom = (BUILD.shadowDom) ? /*@__PURE__*/(() => !!doc.head.attachShadow)() : false;

export const supportsListenerOptions = /*@__PURE__*/(() => {
let supportsListenerOptions = false;
Expand Down
51 changes: 27 additions & 24 deletions src/client/polyfills/index.js
Original file line number Diff line number Diff line change
@@ -1,32 +1,35 @@
export function applyPolyfills() {
var win = window;
if (typeof window !== 'undefined') {
var win = window;

var promises = [];
var promises = [];

if (!win.customElements || (win.Element && (!win.Element.prototype.closest || !win.Element.prototype.matches || !win.Element.prototype.remove))) {
promises.push(import('./dom.js'));
}
if (!win.customElements || (win.Element && (!win.Element.prototype.closest || !win.Element.prototype.matches || !win.Element.prototype.remove))) {
promises.push(import('./dom.js'));
}

function checkIfURLIsSupported() {
try {
var u = new URL('b', 'http://a');
u.pathname = 'c%20d';
return (u.href === 'http://a/c%20d') && u.searchParams;
} catch(e) {
return false;
function checkIfURLIsSupported() {
try {
var u = new URL('b', 'http://a');
u.pathname = 'c%20d';
return (u.href === 'http://a/c%20d') && u.searchParams;
} catch (e) {
return false;
}
}
}

if (
'function' !== typeof Object.assign || !Object.entries ||
!Array.prototype.find || !Array.prototype.includes ||
!String.prototype.startsWith || !String.prototype.endsWith ||
(win.NodeList && !win.NodeList.prototype.forEach) ||
!win.fetch ||
!checkIfURLIsSupported() ||
typeof WeakMap == 'undefined'
) {
promises.push(import('./core-js.js'));
if (
'function' !== typeof Object.assign || !Object.entries ||
!Array.prototype.find || !Array.prototype.includes ||
!String.prototype.startsWith || !String.prototype.endsWith ||
(win.NodeList && !win.NodeList.prototype.forEach) ||
!win.fetch ||
!checkIfURLIsSupported() ||
typeof WeakMap == 'undefined'
) {
promises.push(import('./core-js.js'));
}
return Promise.all(promises);
}
return Promise.all(promises);
return Promise.resolve();
}

0 comments on commit 755ff0d

Please sign in to comment.