Skip to content

Commit

Permalink
chore(redirects): remove retiredLocale parameter (#11148)
Browse files Browse the repository at this point in the history
We have been redirecting retired locales to `en-US` with a `?retiredLocale=XX`
parameter to show a retirement message, but this is no longer useful, as those 
locales have been retired for more than 1.5 years, so we remove this behavior.
caugner authored Jun 25, 2024

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature.
1 parent bfd20d4 commit 08f38df
Showing 6 changed files with 102 additions and 225 deletions.
14 changes: 2 additions & 12 deletions client/src/document/index.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import React from "react";
import { useSearchParams, useNavigate } from "react-router-dom";
import { useNavigate } from "react-router-dom";
import useSWR, { mutate } from "swr";

import { WRITER_MODE, PLACEMENT_ENABLED } from "../env";
@@ -25,7 +25,6 @@ import { LocalizedContentNote } from "./molecules/localized-content-note";
import { OfflineStatusBar } from "../ui/molecules/offline-status-bar";
import { TOC } from "./organisms/toc";
import { RenderSideBar } from "./organisms/sidebar";
import { RetiredLocaleNote } from "./molecules/retired-locale-note";
import { MainContentContainer } from "../ui/atoms/page-content";
import { Loading } from "../ui/atoms/loading";
import { ArticleFooter } from "./organisms/article-footer";
@@ -74,7 +73,6 @@ export function Document(props /* TODO: define a TS interface for this */) {
const mountCounter = React.useRef(0);
const documentURL = useDocumentURL();
const locale = useLocale();
const [searchParams] = useSearchParams();

const navigate = useNavigate();

@@ -213,8 +211,6 @@ export function Document(props /* TODO: define a TS interface for this */) {
return null;
}

const retiredLocale = searchParams.get("retiredLocale");

return (
<>
<div className="sticky-header-container">
@@ -223,16 +219,10 @@ export function Document(props /* TODO: define a TS interface for this */) {
</div>
{/* only include this if we are not server-side rendering */}
{!isServer && <OfflineStatusBar />}
{doc.isTranslated ? (
{doc.isTranslated && (
<div className="container">
<LocalizedContentNote isActive={doc.isActive} locale={locale} />
</div>
) : (
retiredLocale && (
<div className="container">
<RetiredLocaleNote locale={retiredLocale} />
</div>
)
)}
<div className="main-wrapper">
<div className="sidebar-container">
26 changes: 0 additions & 26 deletions client/src/document/molecules/retired-locale-note/index.tsx

This file was deleted.

7 changes: 2 additions & 5 deletions libs/fundamental-redirects/index.js
Original file line number Diff line number Diff line change
@@ -106,11 +106,8 @@ const LOCALE_PATTERNS = [
)})(/(?<suffix>.*)|$)`,
"i"
),
({ locale, suffix }) => {
const join = suffix && suffix.includes("?") ? "&" : "?";
return `/${DEFAULT_LOCALE}/${
(suffix || "") + join
}retiredLocale=${RETIRED_LOCALES.get(locale.toLowerCase())}`;
({ suffix }) => {
return `/${DEFAULT_LOCALE}/${suffix || ""}`;
}
),
];
55 changes: 0 additions & 55 deletions testing/integration/headless/test_redirects.py
Original file line number Diff line number Diff line change
@@ -108,58 +108,3 @@ def test_firefox_source_docs_redirects(url, base_url):
def test_misc_redirects(url, base_url):
url["base_url"] = base_url
assert_valid_url(**url)


@pytest.mark.parametrize(
"retired_locale",
(
"ar",
"bg",
"bn",
"ca",
"el",
"fa",
"fi",
"he",
"hi-IN",
"hu",
"id",
"it",
"kab",
"ms",
"my",
"nl",
"pt-PT",
"sv-SE",
"th",
"tr",
"uk",
"vi",
),
)
@pytest.mark.parametrize(
"slug",
[
"",
"/",
"/docs/Web",
"/docs/Web/",
"/search",
"/search/",
"/search?q=video",
"/search/?q=video",
"/settings",
],
)
def test_retired_locale_redirects(base_url, slug, retired_locale):
"""Ensure that requests for retired locales properly redirect."""
resp = request("get", f"{base_url}/{retired_locale}{slug}")
assert resp.status_code == 302
slug_parts = slug.split("?")
expected_slug = slug_parts[0].lstrip("/")
expected_qs = f"?retiredLocale={retired_locale}"
if len(slug_parts) > 1:
expected_qs += f"&{slug_parts[1]}"
assert (
resp.headers["Location"] == f"/en-US/{expected_slug}{expected_qs}"
), f"{resp.headers['Location']} is not /en-US/{expected_slug}{expected_qs}"
29 changes: 3 additions & 26 deletions testing/tests/headless.index.spec.ts
Original file line number Diff line number Diff line change
@@ -229,44 +229,21 @@ test.describe("changing language", () => {
test.describe("viewing retired locales", () => {
test("redirect retired locale to English (document)", async ({ page }) => {
await page.goto(testURL("/ar/docs/Web/Foo"));
expect(page.url()).toBe(testURL("/en-US/docs/Web/Foo/?retiredLocale=ar"));
expect(page.url()).toBe(testURL("/en-US/docs/Web/Foo/"));
expect(await page.innerText("h1")).toBe("<foo>: A test tag");
});

test("redirect retired locale to English (index.json)", async ({ page }) => {
await page.goto(testURL("/ar/docs/Web/Foo/index.json"));
expect(page.url()).toBe(
testURL("/en-US/docs/Web/Foo/index.json?retiredLocale=ar")
);
expect(page.url()).toBe(testURL("/en-US/docs/Web/Foo/index.json"));
expect(await page.isVisible("text=<foo>: A test tag")).toBeTruthy();
});

test("redirect retired locale to English (search with query string)", async ({
page,
}) => {
await page.goto(testURL("/ar/search?q=video"));
expect(page.url()).toBe(testURL("/en-US/search/?q=video&retiredLocale=ar"));
expect(page.url()).toBe(testURL("/en-US/search/?q=video"));
expect(await page.isVisible("text=Search results for: video")).toBeTruthy();
});

test("say the locale was retired", async ({ page }) => {
await page.goto(testURL("/en-US/docs/Web/Foo/?retiredLocale=ar"));
expect(
await page.isVisible("text=The page you requested has been retired")
).toBeTruthy();
// sanity check that it goes away
await page.goto(testURL("/en-US/docs/Web/Foo/"));
expect(
await page.isVisible("text=The page you requested has been retired")
).toBeFalsy();
});

test("not say the locale was retired if viewing a translated page", async ({
page,
}) => {
await page.goto(testURL("/fr/docs/Web/Foo/?retiredLocale=sv-SE"));
expect(
await page.isVisible("text=The page you requested has been retired")
).toBeFalsy();
});
});
Loading

0 comments on commit 08f38df

Please sign in to comment.