-
-
Notifications
You must be signed in to change notification settings - Fork 578
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
Fix language selector invalid value #2635
Fix language selector invalid value #2635
Conversation
🦋 Changeset detectedLatest commit: 2ba9d3d The changes in this PR will be included in the next version bump. This PR includes changesets to release 1 package
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
✅ Deploy Preview for astro-starlight ready!
To edit notification comments on pull requests, go to your Netlify site configuration. |
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.
Oh, nice fix! Would have assumed we needed a bit of extra JS for this.
Are we sure it works? I just tried in Chrome (v131 on macOS 15) and still saw the old behaviour:
picker.mov
Oh, interesting, I did not checked the deploy preview yet but indeed, this works in dev but not in the production version. I wonder why the difference 🤔 I'll investigate a bit more as it would be nice to avoid JS for this if possible somehow. |
I think that the production preview works properly, because it works on my machine :) I'm using Arc v1.29.0 on Windows 11 and here you can see the comparison between current Starlight (left) and preview of this PR (right). Production.works.I.think.mp4PS: I'm sorry that my screen recorder didn't capture the dropdown menu, what are you guys using for recording? |
After investigating a bit more and finding so many cases/bug reports regarding how the I'll have to update this PR to use a JS based approach instead when I get the time.
Depending on the machine I use, I'll either use ScreenFlow or the built-in macOS screen recording tool. |
Turns out after more investigation that in this specific case, I updated the PR with some code to hook to the I made an E2E test for it while adding the code but I did not submit it:
|
@@ -46,4 +46,18 @@ function localizedPathname(locale: string | undefined): string { | |||
} | |||
} | |||
customElements.define('starlight-lang-select', StarlightLanguageSelect); | |||
window.addEventListener('pageshow', (event) => { |
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.
A better event would be resume
from the Document API but it's not available in Safari at the moment.
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.
LGTM 🎉
But I have a question regarding the fallback if no selected index could be determined (see comment 👇)
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.
Thanks @HiDeoo! I’ll admit there’s part of me that is unsure if this is even a “bug” to be fixed or just “how form elements work and are expected to work”, but the thing that we should definitely fix is that switching language should always work (which it doesn’t currently in this scenario because re-selecting a language doesn’t change anything). So I guess this is one approach to fixing that.
I left a couple of queries and also looks like this script takes us 10 bytes over our JS side limit, so that budget would need increasing for CI to pass.
Co-authored-by: Chris Swithinbank <357379+delucis@users.noreply.github.com>
Co-authored-by: Chris Swithinbank <357379+delucis@users.noreply.github.com>
I personally think that the bfcache restoration not respecting the attribute is a bit weird in our scenario and you can only know something is wrong by hooking up to this event (or I updated the branch with your suggestions and also increased the JS size limit as I was waiting to get an approval before doing so. |
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.
Ready for launch! Thanks again @HiDeoo 🙌
This issue fixes an issue where the language selector could have an invalid value when the user navigates back to a page in a different language.
Repro:
http://localhost:4321/
At expected at this point, the page is in English however the language selector is still set to French.
In Chrome & Safari, a refresh of the page would fix the issue. However, in Firefox, a refresh of the page is not enough to fix the issue, you have to manually focus the address bar and press enter again.
This is not something visible with the theme selector as we have some JS code to update the picker when the page is loaded.
Setting the to
autocomplete
attribute tooff
on theselect
element prvent the browser to automatically select a cached value for this field based on the last user input. Our<Select>
component is only used for the theme and theme selector so I applied the change to the component itself.