Skip to content

Commit

Permalink
Revert "Set cookies for all pages" (#5077)
Browse files Browse the repository at this point in the history
  • Loading branch information
rhelmer authored Sep 18, 2024
1 parent 42f9cb1 commit 669e479
Show file tree
Hide file tree
Showing 7 changed files with 38 additions and 70 deletions.
7 changes: 3 additions & 4 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 0 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,6 @@
"stylelint-scss": "^6.6.0",
"tsx": "^4.19.1",
"typescript": "^5.6.2",
"universal-cookie": "^7.2.0",
"yaml": "^2.5.0"
}
}
33 changes: 15 additions & 18 deletions src/TestComponentWrapper.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,28 +8,25 @@ import { PublicEnvProvider } from "./contextProviders/public-env";
import { SessionProvider } from "next-auth/react";
import { ReactAriaI18nProvider } from "./contextProviders/react-aria";
import { getL10nBundles } from "./app/functions/l10n/storybookAndJest";
import { CookiesProvider } from "./contextProviders/cookies";

const l10nBundles = getL10nBundles();

export const TestComponentWrapper = (props: { children: ReactNode }) => {
return (
<CookiesProvider defaultSetOptions={{ path: "/" }}>
<L10nProvider bundleSources={l10nBundles}>
<PublicEnvProvider
publicEnvs={{
PUBLIC_APP_ENV:
/* c8 ignore next */
process.env.STORYBOOK === "true" ? "storybook" : "test",
}}
>
<SessionProvider session={null}>
<ReactAriaI18nProvider locale="en">
{props.children}
</ReactAriaI18nProvider>
</SessionProvider>
</PublicEnvProvider>
</L10nProvider>
</CookiesProvider>
<L10nProvider bundleSources={l10nBundles}>
<PublicEnvProvider
publicEnvs={{
PUBLIC_APP_ENV:
/* c8 ignore next */
process.env.STORYBOOK === "true" ? "storybook" : "test",
}}
>
<SessionProvider session={null}>
<ReactAriaI18nProvider locale="en">
{props.children}
</ReactAriaI18nProvider>
</SessionProvider>
</PublicEnvProvider>
</L10nProvider>
);
};
25 changes: 11 additions & 14 deletions src/app/(proper_react)/layout.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ import { getCountryCode } from "../functions/server/getCountryCode";
import { PageLoadEvent } from "../components/client/PageLoadEvent";
import { getExperimentationId } from "../functions/server/getExperimentationId";
import { getEnabledFeatureFlags } from "../../db/tables/featureFlags";
import { CookiesProvider } from "../../contextProviders/cookies";

export default async function Layout({ children }: { children: ReactNode }) {
const l10nBundles = getL10nBundles();
Expand All @@ -26,18 +25,16 @@ export default async function Layout({ children }: { children: ReactNode }) {
});

return (
<CookiesProvider defaultSetOptions={{ path: "/" }}>
<L10nProvider bundleSources={l10nBundles}>
<ReactAriaI18nProvider locale={getLocale(l10nBundles)}>
<CountryCodeProvider countryCode={countryCode}>
{children}
<PageLoadEvent
experimentationId={getExperimentationId(session?.user ?? null)}
enabledFlags={enabledFlags}
/>
</CountryCodeProvider>
</ReactAriaI18nProvider>
</L10nProvider>
</CookiesProvider>
<L10nProvider bundleSources={l10nBundles}>
<ReactAriaI18nProvider locale={getLocale(l10nBundles)}>
<CountryCodeProvider countryCode={countryCode}>
{children}
<PageLoadEvent
experimentationId={getExperimentationId(session?.user ?? null)}
enabledFlags={enabledFlags}
/>
</CountryCodeProvider>
</ReactAriaI18nProvider>
</L10nProvider>
);
}
6 changes: 4 additions & 2 deletions src/app/components/client/PageLoadEvent.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -50,9 +50,11 @@ export const PageLoadEvent = (props: Props) => {
// record attributions on page load
if (window.location.search?.length > 0) {
if (!cookies.attributionsFirstTouch) {
setCookie("attributionsFirstTouch", window.location.search);
setCookie("attributionsFirstTouch", window.location.search, {
path: "/",
});
}
setCookie("attributionsLastTouch", window.location.search);
setCookie("attributionsLastTouch", window.location.search, { path: "/" });
}
}, [setCookie, cookies.attributionsFirstTouch]);
// This component doesn't render anything.
Expand Down
11 changes: 5 additions & 6 deletions src/app/functions/client/deleteAllCookies.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,10 @@
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */

import { Cookies } from "react-cookie";

export function deleteAllCookies() {
const cookies = new Cookies(null, { path: "/" });
Object.keys(cookies.getAll()).forEach((cookieName) =>
cookies.remove(cookieName),
);
const cookieParts = document.cookie.split(";");
const cookieNames = cookieParts.map((part) => part.trim().split("=")[0]);
cookieNames.forEach((cookieName) => {
document.cookie = `${cookieName}=; expires=Thu, 01 Jan 1970 00:00:00 GMT`;
});
}
25 changes: 0 additions & 25 deletions src/contextProviders/cookies.tsx

This file was deleted.

0 comments on commit 669e479

Please sign in to comment.