-
Notifications
You must be signed in to change notification settings - Fork 32
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Attempt to reload current page in newly-selected version #60
Attempt to reload current page in newly-selected version #60
Conversation
That's a good idea ! |
Codecov ReportAll modified and coverable lines are covered by tests ✅
Additional details and impacted files@@ Coverage Diff @@
## main #60 +/- ##
============================================
- Coverage 64.31% 63.92% -0.39%
- Complexity 1241 1254 +13
============================================
Files 53 53
Lines 3584 3615 +31
============================================
+ Hits 2305 2311 +6
- Misses 1279 1304 +25 ☔ View full report in Codecov by Sentry. |
It just 404s. Which is not-great, I think, but can be useful as "oh this class doesn't exist in version 4" or whatever, so I'm somewhat ok with it as a concept. |
Okay, well maybe we can find some middle ground with this |
We could sort of naively check for a 200-399 response before re-routing? Something like (pseudocode): var headReq= new XMLHttpRequest();
headReq.open('HEAD', url, false);
headReq.send();
if (headReq.status < 200 || headReq.status > 399)
return newVersionIndex;
else
return url; Or something like that. Essentially, the old behaviour unless the page exists |
I like this idea ! |
Yeah I think that's the approach - if it's unsupported it should return a 405 (I think) and the existing behaviour will resurface anyway. I've pushed an update to support this HEAD request |
66a16da
to
0447854
Compare
Thank you for your work and patience, this is a great feature ! |
Thanks @williamdes - though I've just had a cursory glance at the code I wrote and think I might have the conditionals around the wrong way? |
var testRequest = new XMLHttpRequest(); | ||
testRequest.open('HEAD', candidateUrl, false); | ||
testRequest.send(); | ||
if (testRequest.status < 200 || testRequest.status > 399) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
=200 && < 400
@andrewandante I think that's what you wanted?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@williamdes I think I just have line 88 and line 91 around the wrong way.
If the status is lower than 200 or higher than 399, that means the page "doesn't exist" and so we should default.
The pseudo-code I wrote has it that way around, not sure how I managed to mix it up 😅
Inspired by silverstripe/api.silverstripe.org#106
Most of the time when I toggle the version switcher, I'm hoping to see the page I am currently on, but in a different version.
This PR attempts to do that, rather then defaulting to the homepage of the newly-selected version.