Comments (10)
I got the same result as you. Safari seems to force the custom class on the extends.
I did a non elegant fix by forcing the class to use the current class :
/**
* A helper for creating a Location from either an element
* or a URL object/string
*
*/
export class Location extends URL {
constructor(url: URL | string, base: string = document.baseURI) {
super(url.toString(), base);
Object.setPrototypeOf(this, Location.prototype);
}
/**
* The full local path including query params.
*/
get url(): string {
return this.pathname + this.search;
}
/**
* Instantiate a Location from an element's href attribute
* @param el
* @returns new Location instance
*/
static fromElement(el: Element): Location {
const href = el.getAttribute('href') || el.getAttribute('xlink:href') || '';
return new Location(href);
}
/**
* Instantiate a Location from a URL object or string
* @param url
* @returns new Location instance
*/
static fromUrl(url: URL | string): Location {
return new Location(url);
}
}
from swup.
@MrCaumartin I've gone ahead and released the fix as 4.4.3. Thanks again for reporting and let us know if upgrading doesn't solve the issue on your end.
from swup.
I can confirm this is happening in Safari 13.1 and below. Safari 14.1 is working fine. What seems to be happening is that the href is never picked up correctly. Thanks for reporting! We'll do some investigating.
from swup.
This is great work guys! I'm just curious why you keep talking about tomorrow when actually you just keep on keeping on in the night π¦π
from swup.
This seems to be an issue with Safari not accessing the Location.url getter. Strangely, class getters have been supported since Safari 9 if MDN is to be believed.
from swup.
Looks like Safari below 13 doesn't fully support extending custom classes from built-in classes. I'm not sure there's an elegant solution here. We might switch to using Proxy
, but from quick testing this seems impossible to type safely in TS:
export class Location {
url: URL;
constructor(url: Location | URL | string, base = document.baseURI) {
this.url = new URL(url.toString(), base);
return new Proxy(this.url, {
get(target, prop) {
if (prop === 'url') {
return target.pathname + target.search;
}
return Reflect.get(...arguments);
}
});
}
toString(): string {
return this.url.toString();
}
static fromElement(el: Element): Location {
const href = el.getAttribute('href') || el.getAttribute('xlink:href') || '';
return new Location(href);
}
static fromUrl(url: Location | URL | string): Location {
return new Location(url);
}
}
from swup.
@MrCaumartin Nice, your solution looks pretty elegant to me! Especially compared to my nasty proxy version. I'll give this a spin tomorrow and add some unit tests to make sure there's no regressions, but I'm optimistic :)
from swup.
Thank you @daun ! I'm just not sure what problem could cause overriding the prototype.
You will probably not be able to extends this class without overriding the prototype again, but I don't think it's a use case that is needed.
Maybe checking if the prototype is already the good one could be a good idea. I will do some testing on that tomorrow morning.
from swup.
@MrCaumartin Working great in local testing and end-to-end tests keep passing. Created a PR with your fix. I wouldn't know of any negatives of overriding the prototype as we're not extending that class further.
from swup.
Also, I love our new issue templates π
from swup.
Related Issues (20)
- Rethink tests setup for official plugins HOT 5
- pageA goto pageB; butοΌwith diffrent link style; when back to PageA,the links style is losted
- [Feature Request]: Add way to easily listen to ALL hook events HOT 3
- [Feature Request]: Expose AbortController to be able abort request programmatically HOT 20
- Feature: Allow aborting running visits HOT 1
- Ignore errors in user hooks HOT 1
- Importing helpers from CDN module HOT 2
- History navigation ignored when using custom link selector HOT 5
- [Bug]: URL in `visit:start` inconsistent between normal and history visits HOT 4
- Feature: Store parsed html document in visit object HOT 11
- [Solved]: New values in <head> are not updated HOT 2
- [Bug]: [data-swup-ignore-script] issue with Contact Form 7 in Wordpress HOT 4
- Implement tests for official plugins
- [Feature Request]: Add drop-in attribute to swap/replace content of elements outside the swup container HOT 4
- Slim down core
- [Idea]: New plugin for all route-related stuff HOT 3
- [Idea]: Put core plugins inside swup's main repo HOT 4
- Anime.js and Swup.js conflict
- [Feature Request]: Allow to control `options.linkToSelf` via callback function HOT 2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
π Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. πππ
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google β€οΈ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from swup.