• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

mozilla / fx-private-relay / d770386c-4ec4-4262-acd2-d5922c976ef1

24 Jul 2025 03:18PM UTC coverage: 86.288%. Remained the same
d770386c-4ec4-4262-acd2-d5922c976ef1

push

circleci

web-flow
Merge pull request #5730 from mozilla/MPP-4282-bugfix-domain-mock-leak

MPP-4282: (bugfix) Removed Hardcoded Domain in PROD

2736 of 3943 branches covered (69.39%)

Branch coverage included in aggregate %.

0 of 2 new or added lines in 1 file covered. (0.0%)

1 existing line in 1 file now uncovered.

17879 of 19948 relevant lines covered (89.63%)

9.97 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

0.0
/frontend/src/pages/_app.page.tsx
1
/* eslint-disable @typescript-eslint/no-explicit-any */
2
import "../styles/globals.scss";
×
3
import { createElement, useEffect, useRef, useState } from "react";
×
4
import type { AppProps } from "next/app";
5
import { useRouter } from "next/router";
×
6
import { LocalizationProvider, ReactLocalization } from "@fluent/react";
×
7
import { OverlayProvider } from "@react-aria/overlays";
×
8
import ReactGa from "react-ga";
×
9
import { getL10n } from "../functions/getL10n";
×
10
import { AddonDataContext, useAddonElementWatcher } from "../hooks/addon";
×
11
import { ReactAriaI18nProvider } from "../components/ReactAriaI18nProvider";
×
12
import { useIsLoggedIn } from "../hooks/session";
×
13
import { useMetrics } from "../hooks/metrics";
×
14
import {
15
  useGoogleAnalytics,
16
  initGoogleAnalytics,
17
} from "../hooks/googleAnalytics";
×
18
import "@stripe/stripe-js";
×
19

20
function MyApp({ Component, pageProps }: AppProps) {
21
  const router = useRouter();
×
22
  const isLoggedIn = useIsLoggedIn();
×
23
  const googleAnalytics = useGoogleAnalytics();
×
24
  const metricsEnabled = useMetrics();
×
25
  const addonDataElementRef = useRef<HTMLElement>(null);
×
26

27
  const addonData = useAddonElementWatcher(addonDataElementRef);
×
28
  const [l10n, setL10n] = useState<ReactLocalization>(
×
29
    getL10n({ deterministicLocales: true }),
30
  );
31

32
  useEffect(() => {
×
33
    // When pre-rendering and on the first render, we deterministically load the
34
    // `en` bundle.  After that, however, we want to load the bundles relevant
35
    // to the user's preferred locales. (See the `useL10n` hook for more detail
36
    // on why.) Unfortunately we can't load additional needed locales
37
    // asynchronously on the client-side yet using @fluent/react, see
38
    // https://github.com/projectfluent/fluent.js/wiki/ReactLocalization/43a959b35fbf9eea694367f948cfb1387914657c#flexibility
39
    setL10n(getL10n({ deterministicLocales: false }));
×
40
  }, []);
41

42
  useEffect(() => {
×
43
    if (metricsEnabled === "enabled" && !googleAnalytics) {
×
44
      initGoogleAnalytics();
×
45
    }
46
  }, [metricsEnabled, googleAnalytics]);
47

48
  useEffect(() => {
×
49
    if (!googleAnalytics) return;
×
50
    ReactGa.pageview(router.asPath);
×
51
  }, [router.asPath, googleAnalytics]);
52

53
  const [waitingForMsw, setIsWaitingForMsw] = useState(
×
54
    process.env.NEXT_PUBLIC_MOCK_API === "true",
55
  );
56
  useEffect(() => {
×
57
    if (process.env.NEXT_PUBLIC_MOCK_API !== "true") {
×
58
      return;
×
59
    }
60
    (async () => {
×
NEW
61
      const { initialiseApiMocks } = await import("../apiMocks/initialise");
×
NEW
62
      const { mockIds } = await import("../apiMocks/mockData");
×
63

UNCOV
64
      await initialiseApiMocks();
×
65

66
      if (
×
67
        typeof URLSearchParams !== "undefined" &&
×
68
        typeof document !== "undefined"
69
      ) {
70
        // When deploying the frontend with a mocked back-end,
71
        // this query parameter will allow us to automatically "sign in" with one
72
        // of the mock users. This is useful to be able to give testers a link
73
        // in which to see a particular feature:
74
        const searchParams = new URLSearchParams(document.location.search);
×
75
        const mockId = searchParams.get("mockId");
×
76
        const selectedMockId = mockIds.find((id) => id === mockId);
×
77
        if (typeof selectedMockId === "string") {
×
78
          // See `src/hooks/api/api.ts`; this localStorage entry is how we tell the
79
          // API mock what mock data we want to load:
80
          localStorage.setItem("authToken", selectedMockId);
×
81
        }
82
      }
83

84
      setIsWaitingForMsw(false);
×
85
    })();
86
  }, []);
87

88
  if (waitingForMsw) {
×
89
    // As soon as we start rendering the app, it will start sending requests.
90
    // If we're running the demo site, we want to hold off on doing that until
91
    // MSW is fully initialised. Usually, you'd run the initialisation before
92
    // rendering in the first place, but since Next.js handles the start of the
93
    // rendering (which it does to support server-side rendering), we're doing
94
    // it here instead. For more info, see
95
    // https://mswjs.io/docs/integrations/browser#conditionally-enable-mocking
96
    return <></>;
×
97
  }
98

99
  return (
100
    <LocalizationProvider l10n={l10n}>
101
      <ReactAriaI18nProvider>
102
        <AddonDataContext.Provider value={addonData}>
103
          {createElement("firefox-private-relay-addon", {
104
            // The following attributes are set by the add-on,
105
            // and read by the website (via the useAddonElementWatcher hook).
106
            "data-addon-installed": addonData.present,
107
            "data-local-labels": JSON.stringify(addonData.localLabels),
108
            // The following attributes are set by the website,
109
            // and read by the add-on.
110
            // Capitalised boolean for backwards compatibility;
111
            // this element was previously generated by Django:
112
            "data-user-logged-in":
113
              isLoggedIn === "logged-in" ? "True" : "False",
×
114
          })}
115
          <OverlayProvider id="overlayProvider">
116
            <Component {...pageProps} />
117
          </OverlayProvider>
118
        </AddonDataContext.Provider>
119
      </ReactAriaI18nProvider>
120
    </LocalizationProvider>
121
  );
122
}
123
export default MyApp;
×
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2025 Coveralls, Inc