Skip to content

Commit

Permalink
fix: Flakyness on pages that use a hard refresh (#16752)
Browse files Browse the repository at this point in the history
* fix: Flakyness on pages that use a hard refres

Signed-off-by: zomars <zomars@me.com>

* Update Shell.tsx

---------

Signed-off-by: zomars <zomars@me.com>
  • Loading branch information
zomars authored Sep 21, 2024
1 parent 1a60afa commit 6dd8812
Show file tree
Hide file tree
Showing 9 changed files with 21 additions and 16 deletions.
3 changes: 1 addition & 2 deletions apps/web/components/booking/CancelBooking.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,11 @@ import { useCallback, useState } from "react";

import { sdkActionManager } from "@calcom/embed-core/embed-iframe";
import { useLocale } from "@calcom/lib/hooks/useLocale";
import { useRefreshData } from "@calcom/lib/hooks/useRefreshData";
import { collectPageParameters, telemetryEventTypes, useTelemetry } from "@calcom/lib/telemetry";
import type { RecurringEvent } from "@calcom/types/Calendar";
import { Button, Icon, TextArea } from "@calcom/ui";

import { useRefreshData } from "@lib/hooks/useRefreshData";

type Props = {
booking: {
title?: string;
Expand Down
10 changes: 9 additions & 1 deletion apps/web/playwright/fixtures/users.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import type { Page, WorkerInfo } from "@playwright/test";
import type { Browser, Page, WorkerInfo } from "@playwright/test";
import { expect } from "@playwright/test";
import type Prisma from "@prisma/client";
import type { Team } from "@prisma/client";
Expand Down Expand Up @@ -732,6 +732,14 @@ const createUserFixture = (user: UserWithIncludes, page: Page) => {
self,
apiLogin: async (password?: string) =>
apiLogin({ ...(await self()), password: password || user.username }, store.page),
/** Don't forget to close context at the end */
apiLoginOnNewBrowser: async (browser: Browser, password?: string) => {
const newContext = await browser.newContext();
const newPage = await newContext.newPage();
await apiLogin({ ...(await self()), password: password || user.username }, newPage);
// Don't forget to: newContext.close();
return [newContext, newPage] as const;
},
/**
* @deprecated use apiLogin instead
*/
Expand Down
5 changes: 1 addition & 4 deletions apps/web/playwright/managed-event-types.e2e.ts
Original file line number Diff line number Diff line change
Expand Up @@ -185,10 +185,7 @@ test.describe("Managed Event Types", () => {
await saveAndWaitForResponse(memberPage);

// We edit the managed event as original owner
const adminContext = await browser.newContext();
const adminPage = await adminContext.newPage();
const adminUserSnapshot = await adminUser.self();
await apiLogin({ ...adminUserSnapshot, password: adminUserSnapshot.username }, adminPage);
const [adminContext, adminPage] = await adminUser.apiLoginOnNewBrowser(browser);
await adminPage.goto("/event-types");
await adminPage.getByTestId("event-types").locator(`a[title="${teamEventTitle}"]`).click();
await adminPage.waitForURL("event-types/**");
Expand Down
6 changes: 3 additions & 3 deletions apps/web/playwright/organization/booking.e2e.ts
Original file line number Diff line number Diff line change
Expand Up @@ -542,9 +542,9 @@ test.describe("Bookings", () => {
const usernameOutsideOrg = userOutsideOrganization.username;
// Before invite is accepted the booking page isn't available
await expectPageToBeNotFound({ page, url: `/${usernameInOrg}` });
await userOutsideOrganization.apiLogin();
await acceptTeamOrOrgInvite(page);
await userOutsideOrganization.logout();
const [newContext, newPage] = await userOutsideOrganization.apiLoginOnNewBrowser(browser);
await acceptTeamOrOrgInvite(newPage);
await newContext.close();
await test.step("Book through new link", async () => {
await doOnOrgDomain(
{
Expand Down
5 changes: 1 addition & 4 deletions apps/web/playwright/reschedule.e2e.ts
Original file line number Diff line number Diff line change
Expand Up @@ -287,10 +287,7 @@ test.describe("Reschedule Tests", async () => {
const eventType = user.eventTypes.find((e) => e.slug === "opt-in")!;

const confirmBooking = async (bookingId: number) => {
const authedContext = await browser.newContext();
const authedPage = await authedContext.newPage();
const userSnapshot = await user.self();
await apiLogin({ ...userSnapshot, password: userSnapshot.username }, authedPage);
const [authedContext, authedPage] = await user.apiLoginOnNewBrowser(browser);
await authedPage.goto("/bookings/upcoming");
await submitAndWaitForResponse(authedPage, "/api/trpc/bookings/confirm?batch=1", {
action: () => authedPage.locator(`[data-bookingid="${bookingId}"][data-testid="confirm"]`).click(),
Expand Down
4 changes: 3 additions & 1 deletion packages/features/ee/teams/components/TeamListItem.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import { getPlaceholderAvatar } from "@calcom/lib/defaultAvatarImage";
import { getTeamUrlSync } from "@calcom/lib/getBookerUrl/client";
import { useCompatSearchParams } from "@calcom/lib/hooks/useCompatSearchParams";
import { useLocale } from "@calcom/lib/hooks/useLocale";
import { useRefreshData } from "@calcom/lib/hooks/useRefreshData";
import { MembershipRole } from "@calcom/prisma/enums";
import type { RouterOutputs } from "@calcom/trpc/react";
import { trpc } from "@calcom/trpc/react";
Expand Down Expand Up @@ -51,6 +52,7 @@ export default function TeamListItem(props: Props) {
const showDialog = searchParams?.get("inviteModal") === "true";
const [openMemberInvitationModal, setOpenMemberInvitationModal] = useState(showDialog);
const [openInviteLinkSettingsModal, setOpenInviteLinkSettingsModal] = useState(false);
const refreshData = useRefreshData();

const acceptOrLeaveMutation = trpc.viewer.teams.acceptOrLeave.useMutation({
onSuccess: (_data, variables) => {
Expand All @@ -64,7 +66,7 @@ export default function TeamListItem(props: Props) {
const isDifferentOrg = team.isOrganization && team.id !== userOrganizationId;
// If the user team being accepted is a sub-team of different organization or the different organization itself then page must be reloaded to let the session change reflect reliably everywhere.
if (variables.accept && (isSubTeamOfDifferentOrg || isDifferentOrg)) {
window.location.reload();
refreshData();
}
},
});
Expand Down
4 changes: 3 additions & 1 deletion packages/features/shell/Shell.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ import { useBookerUrl } from "@calcom/lib/hooks/useBookerUrl";
import { useCopy } from "@calcom/lib/hooks/useCopy";
import { useLocale } from "@calcom/lib/hooks/useLocale";
import { ButtonState, useNotifications } from "@calcom/lib/hooks/useNotifications";
import { useRefreshData } from "@calcom/lib/hooks/useRefreshData";
import useTheme from "@calcom/lib/hooks/useTheme";
import { isKeyInObject } from "@calcom/lib/isKeyInObject";
import { localStorage } from "@calcom/lib/webstorage";
Expand Down Expand Up @@ -1286,6 +1287,7 @@ function ProfileDropdown() {
const { update, data: sessionData } = useSession();
const { data } = trpc.viewer.me.useQuery();
const [menuOpen, setMenuOpen] = useState(false);
const refreshData = useRefreshData();

if (!data || !ENABLE_PROFILE_SWITCHER || !sessionData) {
return null;
Expand Down Expand Up @@ -1349,7 +1351,7 @@ function ProfileDropdown() {
update({
upId: option.value,
}).then(() => {
window.location.reload();
refreshData();
});
}}
className={classNames("flex w-full", isSelected ? "bg-subtle text-emphasis" : "")}>
Expand Down
File renamed without changes.
File renamed without changes.

0 comments on commit 6dd8812

Please sign in to comment.