Simplify your stack and build anything. Or everything.
Build tomorrow’s web with a modern solution you truly own.
Code-based nature means you can build on top of it to power anything.
It’s time to take back your content infrastructure.

Production - NotFound page infinity loop

default discord avatar
meda_bbdklast year
15

There is a bug/issue with


javascript  <PayloadLivePreview
      refresh={() => router.refresh()}
      serverURL={process.env.NEXT_PUBLIC_SERVER_URL!}
    />  


and

PayloadRedirects

component, everything is ok in dev mode, but when it's on production...

:bigbrain2:
  • default discord avatar
    zed0547last year

    Can you check your redirects implementation is okay? Last time this was raised the redirects setup wasn't proper. This is the website template correct?



    Like the actual redirects collection had wrong data

  • default discord avatar
    meda_bbdklast year

    Yes, website template

  • default discord avatar
    zed0547last year

    Fresh install?

  • default discord avatar
    meda_bbdklast year

    almost fresh



    I just added few things

  • default discord avatar
    zed0547last year

    Seeded right? And what Payload version?



    What does your redirects collection look like

  • default discord avatar
    meda_bbdklast year

    latest, this bug is from 1m ago, The only that helped me was to create a root layout before (the frontend) and (payload), but that caused some other bugs



    the reason why I create a "new" fresh project is just to see what is wrong... It's really annoying...

  • default discord avatar
    zed0547last year

    This has been brought up a few times before and no ones been able to have a consistent reproduction so far

  • default discord avatar
    meda_bbdklast year

    1st time when I realized that I had a bug

  • default discord avatar
    zed0547last year
    @858693520012476436

    its this thing again



    In a video call Ivan showed that wrapping the (frontend) + (backend) in a root layout actually fixes it with some obvious side effects of invalid html structure

  • default discord avatar
    meda_bbdklast year

    I did my best to reproduce the error...

  • default discord avatar
    judgejbrownlast year

    I had this issue when I added versioning and live pre-views

    after

    my pages were created. My fix was simply deleting my exisiting pages and remaking them.

  • default discord avatar
    meda_bbdklast year

    I finally fix it!!!!!

    @654031862146007055

    @858693520012476436

    here is the solution



    'use client';
    import { RefreshRouteOnSave as PayloadLivePreview } from '@payloadcms/live-preview-react';
    import { useRouter } from 'next/navigation';
    import React, { useState } from 'react';
    
    export const LivePreviewListener: React.FC = () => {
      const router = useRouter();
      const [hasError, setHasError] = useState(false);
    
      // Error handling function
      const handleRefresh = async () => {
        try {
          // Perform a fetch request to check if the current route exists
          const response = await fetch(window.location.href, {
            method: 'HEAD',
            cache: 'no-store',
          });
    
          console.log(
            'Response status:',
            response.status,
            'Response status text:',
            response.statusText,
          );
    
          // If the response is not OK (status code is not 2xx), set error state
          if (!response.ok) {
            setHasError(true);
          } else {
            // Otherwise, refresh the route
            router.refresh();
          }
        } catch (error) {
          // Catch any network errors and set error state
          console.error('Error checking route:', error);
          setHasError(true);
        }
      };
    
      // Return null if there's an error
      if (hasError) {
        return null;
      }
    
      return (
        <PayloadLivePreview
          refresh={handleRefresh}
          serverURL={process.env.NEXT_PUBLIC_SERVER_URL!}
        />
      );
    };


    :niceone:

    :payloadlove:
  • default discord avatar
    miguelstevensbelast year

    Hey

    @402788885366833183

    what version of live-preview-react are you requiring in package.json?



    I'm getting

    Module '"@payloadcms/live-preview-react"' has no exported member 'RefreshRouteOnSave'.ts(2305)
  • default discord avatar
    meda_bbdklast year

    Latest? You?

  • default discord avatar
    _mel.tslast year

    THANKYOU

    @402788885366833183

    🙏

Star on GitHub

Star

Chat on Discord

Discord

online

Can't find what you're looking for?

Get dedicated engineering support directly from the Payload team.