Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

PYTHON-4212: Wrap useSearchParams() function components in suspense boundaries #28

Merged
merged 2 commits into from
Feb 27, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 17 additions & 14 deletions {{cookiecutter.project_slug}}/frontend/app/login/page.tsx
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
"use client";

import { useAppDispatch, useAppSelector } from "../lib/hooks";
import { login, loggedIn } from "../lib/slices/authSlice";
import { useRouter, useSearchParams } from "next/navigation";
import { tokenIsTOTP, tokenParser } from "../lib/utilities";
import { Switch } from "@headlessui/react";
import { useEffect, useState } from "react";
"use client"

import { useAppDispatch, useAppSelector } from "../lib/hooks"
import { login, loggedIn } from "../lib/slices/authSlice"
import { useRouter, useSearchParams } from "next/navigation"
import { tokenIsTOTP, tokenParser } from "../lib/utilities"
import { Switch } from "@headlessui/react"
import { Suspense, useEffect, useState } from "react"
import {
FieldErrors,
FieldValues,
Expand Down Expand Up @@ -101,12 +101,11 @@ function LoginMessage(oauth: boolean) {
);
}

export default function Page() {
const [oauth, setOauth] = useState(false);
const dispatch = useAppDispatch();
const accessToken = useAppSelector((state) => state.tokens.access_token);
const isLoggedIn = useAppSelector((state) => loggedIn(state));

function UnsuspendedPage() {
const [oauth, setOauth] = useState(false)
const dispatch = useAppDispatch()
const accessToken = useAppSelector((state) => state.tokens.access_token)
const isLoggedIn = useAppSelector((state) => loggedIn(state))
const searchParams = useSearchParams();
const router = useRouter();

Expand Down Expand Up @@ -249,3 +248,7 @@ export default function Page() {
</main>
);
}

export default function Page() {
return <Suspense><UnsuspendedPage /></Suspense>
}
27 changes: 15 additions & 12 deletions {{cookiecutter.project_slug}}/frontend/app/page.tsx
Original file line number Diff line number Diff line change
@@ -1,14 +1,13 @@
"use client";

import { ChevronRightIcon } from "@heroicons/react/20/solid";
import Link from "next/link";
import { useRouter, useSearchParams } from "next/navigation";
import { useEffect } from "react";
import { useAppDispatch, useAppSelector } from "./lib/hooks";
import { loggedIn, magicLogin } from "./lib/slices/authSlice";
import { tokenIsTOTP } from "./lib/utilities";
import { token } from "./lib/slices/tokensSlice";

import { ChevronRightIcon } from "@heroicons/react/20/solid"
import Link from "next/link"
import { useRouter, useSearchParams } from "next/navigation"
import { Suspense, useEffect } from "react"
import { useAppDispatch, useAppSelector } from "./lib/hooks"
import { loggedIn, magicLogin } from "./lib/slices/authSlice"
import { tokenIsTOTP } from "./lib/utilities"
import { token } from "./lib/slices/tokensSlice"
const github = {
name: "GitHub",
href: "https://github.com/mongodb-labs/full-stack-fastapi-mongodb",
Expand All @@ -28,9 +27,9 @@ const github = {
const redirectTOTP = "/totp";
const redirectAfterLogin = "/";

export default function Page() {
const router = useRouter();
const query = useSearchParams();
function UnsuspendedPage() {
const router = useRouter()
const query = useSearchParams()

const dispatch = useAppDispatch();

Expand Down Expand Up @@ -180,3 +179,7 @@ export default function Page() {
</main>
);
}

export default function Page() {
return <Suspense><UnsuspendedPage /></Suspense>
}
20 changes: 12 additions & 8 deletions {{cookiecutter.project_slug}}/frontend/app/reset-password/page.tsx
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
"use client";

import { useRouter, useSearchParams } from "next/navigation";
import { useAppDispatch } from "../lib/hooks";
import { useForm } from "react-hook-form";
import { resetPassword } from "../lib/slices/authSlice";
import { useEffect } from "react";
import Image from "next/image";
import { useRouter, useSearchParams } from "next/navigation"
import { useAppDispatch } from "../lib/hooks"
import { useForm } from "react-hook-form"
import { resetPassword } from "../lib/slices/authSlice"
import { Suspense, useEffect } from "react"
import Image from "next/image"

const schema = {
password: { required: true, minLength: 8, maxLength: 64 },
Expand Down Expand Up @@ -34,8 +34,8 @@ const renderError = (type: LiteralUnion<keyof RegisterOptions, string>) => {
}
};

export default function ResetPassword() {
const dispatch = useAppDispatch();
function UnsuspendedResetPassword() {
const dispatch = useAppDispatch()

const router = useRouter();
const query = useSearchParams();
Expand Down Expand Up @@ -154,3 +154,7 @@ export default function ResetPassword() {
</main>
);
}

export default function ResetPassword() {
return <Suspense><UnsuspendedResetPassword /></Suspense>
}