cloudinary / cloudinary_npm

Cloudinary NPM for node.js integration
629 stars 322 forks source link

Photo Query Page updates dynamically in local machine, but failed to update dynamically after deployment to Cloudflare or Netlify #665

Closed Krystino closed 4 months ago

Krystino commented 4 months ago

Bug report for Cloudinary NPM SDK

Before proceeding, please update to latest version and test if the issue persists

Describe the bug in a sentence or two.

image

Hello, sir. My Photo list Page updates dynamically in local machine, but failed to update the photo list dynamically after deployment to Cloudflare or Netlify.

My Repo

photo for display (not updating after deployment)

import CImage from "./image";

type Results = {
  public_id: string,
  width: string,
  height: string,
}

type SearchResult = {
  resources: Results[]
}

export const dynamic = 'force-dynamic';

export default async function GalleryPage() {
  let { resources } = await cloudinary.v2.search
    .expression("resource_type:image")
    .sort_by("created_at", "desc")
    .max_results()
    .execute() as SearchResult;

  return (
    <section>
      <div className="flex justify-between">
        <h1 className="text-4xl font-bold">图库</h1>
        <UploadButton/>
      </div>
      <div className="grid grid-cols-2 sm:grid-cols-4 gap-4 mt-10">
        {
          resources.map( ({public_id, width, height} ) =>
            <CImage src={public_id} key={public_id} width={width} height={height}/>
          )
        }
      </div>

    </section>)
}

photo component image.tsx:

"use client";

import { CldImage } from 'next-cloudinary';
import { OvalLoveTwo } from '@icon-park/react'

export default function CImage(props: any) {
  return (
    <div className='relative'>
      <CldImage
        width="300"
        height="300"
        sizes="100vw"
        alt="Description of my image"
        {...props}
      />
      <OvalLoveTwo className='absolute top-2 right-2' fill="#FFFFFF"  />
    </div>
  )
}

the upload button that triggers page refresh:

"use client";

import { CldUploadButton } from 'next-cloudinary';
import { Button } from "@/components/ui/button"
import { Upload } from '@icon-park/react';
import { useRouter } from 'next/navigation';

export default function UploadButton() {
  const router = useRouter()
  return (
    <Button asChild>
      <CldUploadButton
        uploadPreset="PhotoHub"
        onSuccess={()=>{
          router.refresh() // refersh the whole page
        }
      }>
        <Upload theme="outline" size="18" fill="#000000" strokeWidth={2} strokeLinecap="butt"/>
        <span className='pl-2'>上传图片</span>
      </CldUploadButton>
    </Button>
  )
}

Issue Type (Can be multiple)

[ ] Build - Can’t install or import the SDK [ ] Babel - Babel errors or cross browser issues [ ] Performance - Performance issues [x] Behaviour - Functions aren’t working as expected (Such as generate URL) [ ] Documentation - Inconsistency between the docs and behaviour [ ] Incorrect Types - For typescript users who are having problems with our d.ts files [x] Other (Specify)

Steps to reproduce

Open My Repo locally and deploy it online. Online URL deployed is: https://main--photo-hubs.netlify.app/

Error screenshots

… if applicable

Browsers (if issue relates to UI, else ignore)

[ ] Chrome [ ] Firefox [ ] Safari [ ] Other (Specify) [ ] All

Versions and Libraries (fill in the version numbers)

Cloudinary_NPM SDK version 2.2.0 Node - 0.0.0 NPM - 0.0.0

Config Files (Please paste the following files if possible)

{
  "name": "photohub",
  "version": "0.1.0",
  "private": true,
  "scripts": {
    "dev": "next dev",
    "build": "next build",
    "start": "next start",
    "lint": "next lint"
  },
  "dependencies": {
    "@icon-park/react": "^1.4.2",
    "@radix-ui/react-avatar": "^1.0.4",
    "@radix-ui/react-dropdown-menu": "^2.0.6",
    "@radix-ui/react-slot": "^1.0.2",
    "@types/node": "20.14.2",
    "@types/react": "18.3.3",
    "@types/react-dom": "18.3.0",
    "autoprefixer": "10.4.19",
    "class-variance-authority": "^0.7.0",
    "cloudinary": "^2.2.0",
    "clsx": "^2.1.1",
    "eslint": "8.57.0",
    "eslint-config-next": "14.2.4",
    "lucide-react": "^0.395.0",
    "next": "14.2.4",
    "next-cloudinary": "^6.6.2",
    "postcss": "8.4.38",
    "react": "18.3.1",
    "react-dom": "18.3.1",
    "tailwind-merge": "^2.3.0",
    "tailwindcss": "3.4.4",
    "tailwindcss-animate": "^1.0.7",
    "typescript": "5.4.5"
  }
}

Repository

My Repo

dannyv-cloudinary commented 4 months ago

Hi, thanks for the report. This seems to be an issue with the deployment location, rather than our library. I'm afraid we won't be able to help directly, but typically when we see issues with deployments to Netlify (or other services) it's often related to environment variables not being correctly configured. I hope that helps point you on the right path to solving this. Failing that, it may be worth posting on a community such as StackOverflow.