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

fix useSearchParams usage bug #184

Merged
merged 1 commit into from
May 29, 2023
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
13 changes: 3 additions & 10 deletions apps/www/components/provider.tsx
Original file line number Diff line number Diff line change
@@ -1,22 +1,14 @@
'use client';

import React, { useEffect } from 'react';
import { usePathname, useSearchParams } from 'next/navigation';
import React from 'react';
import { Toaster, Tooltip } from '@opub-cdl/ui';
import { QueryClient, QueryClientProvider } from '@tanstack/react-query';
import NextTopLoader from 'nextjs-toploader';
import { SSRProvider } from 'react-aria';

import { navigateEnd } from '@/lib/navigation';
import { RouterEvents } from '@/lib/navigation';

export default function Provider({ children }: { children: React.ReactNode }) {
const pathname = usePathname();
const searchParams = useSearchParams();

useEffect(() => {
navigateEnd();
}, [pathname, searchParams]);

const [client] = React.useState(
new QueryClient({
defaultOptions: {
Expand All @@ -32,6 +24,7 @@ export default function Provider({ children }: { children: React.ReactNode }) {
return (
<QueryClientProvider client={client}>
<SSRProvider>
<RouterEvents />
<NextTopLoader color="var(--decorative-icon-three)" />
<Tooltip.Provider>
{children}
Expand Down
13 changes: 0 additions & 13 deletions apps/www/lib/navigation.ts

This file was deleted.

35 changes: 35 additions & 0 deletions apps/www/lib/navigation.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
import React from 'react';
import { usePathname, useSearchParams } from 'next/navigation';
import NProgress from 'nprogress';

import { useIsNavigating } from '@/config/store';

export function navigateStart() {
NProgress.start();
useIsNavigating.getState().setIsNavigation(true);
}

export function navigateEnd() {
NProgress.done();
useIsNavigating.getState().setIsNavigation(false);
}

function useOnComplete() {
const pathname = usePathname();
const searchParams = useSearchParams();
React.useEffect(() => navigateEnd(), [pathname, searchParams]);
}

function __RouterEvents() {
useOnComplete();
return null;
}

// https://github.com/joulev/nextjs13-appdir-router-events/blob/52e3457f183b0b638cd14c6c0e8c138e71a76895/app/router-events.tsx
export function RouterEvents() {
return (
<React.Suspense>
<__RouterEvents />
</React.Suspense>
);
}