From a249b2a608b84afc3fa9eee4cafcf1aad5ae5b21 Mon Sep 17 00:00:00 2001 From: Nolan Lawson Date: Sun, 7 Jan 2018 23:00:15 -0800 Subject: [PATCH] add URLSearchParams polyfill --- package-lock.json | 5 +++++ package.json | 1 + templates/main.js | 17 +++++++++++++++-- 3 files changed, 21 insertions(+), 2 deletions(-) diff --git a/package-lock.json b/package-lock.json index b4e3de4..737f0ca 100644 --- a/package-lock.json +++ b/package-lock.json @@ -5011,6 +5011,11 @@ } } }, + "url-search-params": { + "version": "0.10.0", + "resolved": "https://registry.npmjs.org/url-search-params/-/url-search-params-0.10.0.tgz", + "integrity": "sha512-oFPzmbPAbdthStgffGq8alULe47skPDt1X3KW6NOQnKkcLHP4IS1NfdfHG/CBP5lGsr2gDzNp87pfWLx/eIxjw==" + }, "util": { "version": "0.10.3", "resolved": "https://registry.npmjs.org/util/-/util-0.10.3.tgz", diff --git a/package.json b/package.json index 3cb36e4..7315056 100644 --- a/package.json +++ b/package.json @@ -27,6 +27,7 @@ "svelte": "^1.50.0", "svelte-loader": "^2.3.3", "uglifyjs-webpack-plugin": "^1.1.5", + "url-search-params": "^0.10.0", "webpack": "^3.10.0" }, "engines": { diff --git a/templates/main.js b/templates/main.js index aa08cb0..a94f56d 100644 --- a/templates/main.js +++ b/templates/main.js @@ -1,4 +1,17 @@ import { init } from 'sapper/runtime.js'; -// `routes` is an array of route objects injected by Sapper -init(document.querySelector('#sapper'), __routes__); \ No newline at end of file +// polyfills +Promise.all([ + typeof URLSearchParams === 'undefined' && import('url-search-params').then(Params => { + window.URLSearchParams = Params + Object.defineProperty(window.URL.prototype, 'searchParams', { + get() { + return new Params(this.search) + } + }) + }) +]).then(() => { + console.log('done') + // `routes` is an array of route objects injected by Sapper + init(document.querySelector('#sapper'), __routes__) +}) \ No newline at end of file