code: public function isPreviewMode(): bool
      {
          $token = $this->getToken(FrontendUser::SECURITY_SESSION_KEY);
  
          return $token instanceof FrontendPreviewToken && $token->showUnpublished();
      }
docs: Tells whether the front end preview can show unpublished fragments.