Skip to content

Conversation

@DianaSuvorova
Copy link
Collaborator

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

@cloudflare-workers-and-pages
Copy link

Deploying baseweb with  Cloudflare Pages  Cloudflare Pages

Latest commit: b496cd1
Status: ✅  Deploy successful!
Preview URL: https://f3802b66.baseweb.pages.dev
Branch Preview URL: https://versionselector.baseweb.pages.dev

View logs

Copy link

Copilot AI left a 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 handleVersionSelect async 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.

Comment on lines +36 to +53
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/';
}
Copy link

Copilot AI Jan 6, 2026

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:

  1. The fetch will be blocked by CORS policy (different subdomain = different origin)
  2. 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)
Suggested 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;

Copilot uses AI. Check for mistakes.
Comment on lines +67 to 68
handleVersionSelect(item);
close();
Copy link

Copilot AI Jan 6, 2026

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.

Copilot uses AI. Check for mistakes.
Comment on lines +67 to 68
handleVersionSelect(item);
close();
Copy link

Copilot AI Jan 6, 2026

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:

  1. Await the handleVersionSelect call: await handleVersionSelect(item);
  2. Call close() only after the fetch completes (move it into handleVersionSelect)
  3. Provide loading feedback while the check is in progress

Copilot uses AI. Check for mistakes.
@dyesin dyesin merged commit c865b47 into main Jan 7, 2026
11 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants