-
Notifications
You must be signed in to change notification settings - Fork 858
Doc Site: Navigate to home if version subdomain does not exist #5382
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
Conversation
Deploying baseweb with
|
| Latest commit: |
b496cd1
|
| Status: | ✅ Deploy successful! |
| Preview URL: | https://f3802b66.baseweb.pages.dev |
| Branch Preview URL: | https://versionselector.baseweb.pages.dev |
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.
Pull request overview
This PR modifies the version selector component to check if a version subdomain exists before navigating to it. If the subdomain is not available, users are redirected to the main site (https://baseweb.design/) instead. This addresses an issue where some version subdomains (like v15) are not configured, while others (like v8) are.
Key changes:
- Added
handleVersionSelectasync function that performs a HEAD request to check subdomain availability - Changed navigation from opening in a new tab (
window.open) to navigating in the current tab (window.location.href) - Added error handling to redirect to the main site when subdomains don't exist
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| const handleVersionSelect = async (item) => { | ||
| const versionUrl = `https://${item.label}.baseweb.design`; | ||
|
|
||
| try { | ||
| // Check if the version page exists | ||
| const response = await fetch(versionUrl, { method: 'HEAD' }); | ||
|
|
||
| if (response.ok) { | ||
| // Page exists, navigate to it | ||
| window.location.href = versionUrl; | ||
| } else { | ||
| // Page doesn't exist, redirect to main site | ||
| window.location.href = 'https://baseweb.design/'; | ||
| } | ||
| } catch (error) { | ||
| // In case of network error, redirect to main site | ||
| window.location.href = 'https://baseweb.design/'; | ||
| } |
Copilot
AI
Jan 6, 2026
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.
The HEAD request to check if the version subdomain exists will likely fail due to CORS (Cross-Origin Resource Sharing) restrictions. Browsers block cross-origin HEAD requests to different subdomains unless the server explicitly allows them with CORS headers. When the fetch fails due to CORS, it will be caught by the catch block and redirect to the main site, which means the check won't work as intended.
This approach will always redirect to the main site because:
- The fetch will be blocked by CORS policy (different subdomain = different origin)
- The catch block will catch the CORS error and redirect to https://baseweb.design/
Consider alternative approaches:
- Maintain a hardcoded list/set of valid version subdomains in the code
- Use a server-side endpoint on the current domain that checks version availability
- Configure all version subdomains to include appropriate CORS headers (infrastructure change)
| const handleVersionSelect = async (item) => { | |
| const versionUrl = `https://${item.label}.baseweb.design`; | |
| try { | |
| // Check if the version page exists | |
| const response = await fetch(versionUrl, { method: 'HEAD' }); | |
| if (response.ok) { | |
| // Page exists, navigate to it | |
| window.location.href = versionUrl; | |
| } else { | |
| // Page doesn't exist, redirect to main site | |
| window.location.href = 'https://baseweb.design/'; | |
| } | |
| } catch (error) { | |
| // In case of network error, redirect to main site | |
| window.location.href = 'https://baseweb.design/'; | |
| } | |
| const handleVersionSelect = (item) => { | |
| const versionUrl = `https://${item.label}.baseweb.design`; | |
| // Navigate directly to the selected version; let the server handle missing pages. | |
| window.location.href = versionUrl; |
| handleVersionSelect(item); | ||
| close(); |
Copilot
AI
Jan 6, 2026
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.
The navigation behavior has changed from opening the version in a new tab/window (window.open) to navigating in the current tab (window.location.href). This is a breaking change in user experience that should be intentional.
If this change is intentional, consider:
- The popover close() is called after handleVersionSelect, but since handleVersionSelect is async and doesn't await anything before navigation, the close() will execute before the navigation completes
- Users may expect the new behavior to open in a new tab (as before) to preserve their current page context
If this wasn't an intentional change, restore window.open() behavior while still checking for version existence.
| handleVersionSelect(item); | ||
| close(); |
Copilot
AI
Jan 6, 2026
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.
The async function handleVersionSelect is called without await, and then close() is called immediately. This creates a race condition where the popover closes before the async check completes. If the fetch takes time to fail (network timeout), the popover will close but the navigation won't happen yet, leaving the user without feedback.
Consider one of these approaches:
- Await the handleVersionSelect call:
await handleVersionSelect(item); - Call close() only after the fetch completes (move it into handleVersionSelect)
- Provide loading feedback while the check is in progress
Some releases are configured to have subdomains:
for example https://v8.baseweb.design/
but some are not https://v15.baseweb.design/
this corrects the version selector behaviour, so it will redirect to home https://baseweb.design/ in case subdomain is not configured