react-hot-toast icon indicating copy to clipboard operation
react-hot-toast copied to clipboard

Warning when doing ssr

Open veritem opened this issue 3 years ago • 9 comments

I'm using remix but the warning persist image

How can i fix it?

veritem avatar Jan 15 '22 14:01 veritem

I found how to fix it thanks 👍

veritem avatar Jan 23 '22 12:01 veritem

I am seeing same warning in next.js app. Fixed that by putting the Toaster component inside HOC which renders children only in client-side

snax4a avatar May 28 '22 12:05 snax4a

I found how to fix it thanks 👍

@veritem I am facing the same issue for Remix JS project. What was the solution?

shubhenducw avatar Jun 10 '22 15:06 shubhenducw

@shubhenducw you need to import <Toaster> in root.tsx and add it bellow <Outlet/> in your root component

veritem avatar Jun 10 '22 16:06 veritem

Fixed it in Remix.run by using <ClientOnly /> from remix-utils:

          <Outlet />
          <ClientOnly fallback={<p>Loading...</p>}>
            {() => (
              <Toaster
                toastOptions={{
                  success: {
                    style: {
                      background: "black",
                      color: "white",
                    },
                  },
                }}
              />
            )}
          </ClientOnly>
          <ScrollRestoration />
          <Scripts />
          <LiveReload />

gijs avatar Jun 15 '22 19:06 gijs

hi @veritem, I wonder if you can share the code for the fix, I don't know how to fix it.

pablogravielseo avatar Aug 08 '22 18:08 pablogravielseo

Here is a snippet of how to do it in your root.tsx add Screen Shot 2022-08-08 at 9 31 41 PM

veritem avatar Aug 08 '22 19:08 veritem

Just noting here, all of these fixes are phrased around NextJS and Remix.run. I wish that we weren't coupling server architecture into the fix. How do we resolve this just using SSR with React 18?

toddtarsi avatar Oct 27 '22 22:10 toddtarsi

I figured it out. If you want to avoid having SSR issues, just do this for React 18:

<React.Suspense>
  <Toaster />
</React.Suspense>

toddtarsi avatar Oct 28 '22 19:10 toddtarsi