question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Spread operators in object literals cause crashes in Edge/EdgeHTML

See original GitHub issue

Bug Report

naja built source contains spread operator (...) in object literals, which is ES2018 feature. But Edge 12-18 (with EdgeHTML core) throws syntax error, because they implement only ES2015.

In the migration guide from v1 to v2, there is only mentioned that IE is no more supported, no mention about Edge. But .browserslistrc list last 2 versions which mean that old Edges with EdgeHTML core do not match anymore.

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:11 (8 by maintainers)

github_iconTop GitHub Comments

1reaction
jiripudilcommented, Sep 2, 2020

I mean, you can always tweak your build configuration to further transpile naja if you need to support any ancient browser (Edge 16 is almost 3 years old). It just doesn’t make sense to me for Naja itself to support anything else than the latest version.

0reactions
dakurcommented, Sep 2, 2020

I’ve created this patch for myself quickly and found no further problem in Edge 18.

diff --git a/node_modules/naja/dist/Naja.esm.js b/node_modules/naja/dist/Naja.esm.js
index bd4b5c5..e61823c 100644
--- a/node_modules/naja/dist/Naja.esm.js
+++ b/node_modules/naja/dist/Naja.esm.js
@@ -1172,12 +1172,8 @@ class Naja extends EventTarget {
       url = url.href;
     }
 
-    options = { ...this.defaultOptions,
-      ...options,
-      fetch: { ...(this.defaultOptions.fetch || {}),
-        ...(options.fetch || {})
-      }
-    };
+    const fetchOptions = Object.assign({}, this.defaultOptions.fetch || {}, options.fetch || {});
+    options = Object.assign({}, this.defaultOptions, options, {fetch: fetchOptions});
 
     if (method.toUpperCase() === 'GET' && data instanceof FormData) {
       const urlObject = new URL(url, location.href);
@@ -1191,14 +1187,15 @@ class Naja extends EventTarget {
     }
 
     const abortController = new AbortController();
-    const request = new Request(url, {
-      credentials: 'same-origin',
-      ...options.fetch,
-      method,
-      headers: new Headers(options.fetch.headers || {}),
-      body: data !== null && Object.getPrototypeOf(data) === Object.prototype ? new URLSearchParams(data) : data,
-      signal: abortController.signal
-    }); // impersonate XHR so that Nette can detect isAjax()
+
+    const requestOptions = Object.assign({}, {
+		credentials: 'same-origin',
+		method,
+		headers: new Headers(options.fetch.headers || {}),
+		body: data !== null && Object.getPrototypeOf(data) === Object.prototype ? new URLSearchParams(data) : data,
+		signal: abortController.signal
+	}, options.fetch);
+    const request = new Request(url, requestOptions);
 
     request.headers.set('X-Requested-With', 'XMLHttpRequest');
Read more comments on GitHub >

github_iconTop Results From Across the Web

Spread syntax (...) - JavaScript - MDN Web Docs - Mozilla
In an object literal, the spread syntax enumerates the properties of an object and adds the key-value pairs to the object being created....
Read more >
Why is this spread operator causing a SyntaxError
It's a parsing error that's detected before your program even starts running. Crashes are when your program compiles/parses OK, but does an ...
Read more >
What's the Spread Operator Used For in JavaScript?
The spread operator spreads these values within a new object of the same type; in this case, an array literal. Try running the...
Read more >
Spreads: Common Errors & Fixes - Flow - Medium
In v0.111 the Flow team is rolling out a ton of fixes to object spreads (spreading an object in an expression, see “Spread...
Read more >
JavaScript operator: Spread syntax (...): Spread in object literals
"Can I use" provides up-to-date browser support tables for support of front-end web technologies on desktop and mobile web browsers.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found