ndungtse / next13-progressbar

A simple Next.js progressbar component using NProgress with support of next.js >=13 app dir.
https://next13-progressbar.vercel.app
MIT License
91 stars 3 forks source link

A change in Next.js 14.1 causes the build to fail #18

Closed njbmartin closed 8 months ago

njbmartin commented 8 months ago

Describe the bug

Next.js 14.1 introduced this:

Builds will now fail on incorrect usage of useSearchParams without Suspense.

It was a rather unhelpful error, but luckily didn't take me too long to discover that Next13 Progressbar is where the problem is occurring.

useSearchParams() should be wrapped in a suspense boundary at page "/404". Read more: https://nextjs.org/docs/messages/missing-suspense-with-csr-bailout

Error occurred prerendering page "/_not-found". Read more: https://nextjs.org/docs/messages/prerender-error

Also an easy fix on my end:

'use client';
import React, { Suspense } from 'react';
import { Next13ProgressBar } from 'next13-progressbar';
import SupabaseProvider from './supabase-provider';

const Providers = ({ children }: { children: React.ReactNode }) => {
  return (
    <>
      <SupabaseProvider>
        {children}
        <Suspense>
          <Next13ProgressBar
            height="2px"
            color="rgb(219, 39, 119)"
            showOnShallow
            options={{ showSpinner: false }}
          />
        </Suspense>
      </SupabaseProvider>
    </>
  );
};

export default Providers;
ndungtse commented 8 months ago

@njbmartin according to the latest release of next.js this is a serious issue but I'm wondering if we can introduce feature of wrapping suspense inside the package or just update docs adding exception to the version >= 14.1. What do you think? Cause again may be the user will not always use react suspense 💁🏽‍♂️