Skip to content
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

Merged

Conversation

andrewandante
Copy link
Contributor

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.

@williamdes
Copy link
Member

That's a good idea !
What does it do when it does not exist on the target version ?

@codecov
Copy link

codecov bot commented Oct 10, 2023

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 63.92%. Comparing base (2ca5517) to head (0447854).
Report is 23 commits behind head on main.

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.
📢 Have feedback on the report? Share it here.

@andrewandante
Copy link
Contributor Author

That's a good idea ! What does it do when it does not exist on the target version ?

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.

@williamdes
Copy link
Member

That's a good idea ! What does it do when it does not exist on the target version ?

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
Maybe asking the search bar to load the page that we where on before
Like some return_to argument

@andrewandante
Copy link
Contributor Author

andrewandante commented Oct 11, 2023

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

@williamdes
Copy link
Member

I like this idea !
Not all servers support HEAD, but we can agree to say that they should and ignore this corner case.
Or just try using GET if the first one fails

@andrewandante
Copy link
Contributor Author

andrewandante commented Oct 11, 2023

agree to say that they should

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

@andrewandante andrewandante force-pushed the ENH/reload_page_in_current_version branch from 66a16da to 0447854 Compare October 11, 2023 21:19
@williamdes williamdes added this to the v5.6.0 milestone Dec 16, 2023
@williamdes williamdes self-assigned this Apr 6, 2024
@williamdes williamdes added the enhancement New feature or request label Apr 6, 2024
@williamdes williamdes changed the title ENH attempt to reload current page in newly-selected version Attempt to reload current page in newly-selected version Apr 6, 2024
williamdes added a commit that referenced this pull request Apr 6, 2024
@williamdes williamdes merged commit 865cbaf into code-lts:main Apr 6, 2024
24 of 33 checks passed
@williamdes
Copy link
Member

Thank you for your work and patience, this is a great feature !

@andrewandante
Copy link
Contributor Author

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) {
Copy link
Member

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?

Copy link
Contributor Author

@andrewandante andrewandante Apr 7, 2024

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 😅

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Development

Successfully merging this pull request may close these issues.

2 participants