skip to Main Content

I am a next.js developer.

I have a blog and want to search a keyword in title of my posts.

this is part of my code.

const [result, setresult] = useState([]);
const [keyword, setkeyword] = useState(url.keyword ? `&keyword=${url.keyword}` : "");

  useEffect(() => {

      axios
         .get(
            `https://example.com/api/search-posts?${keyword}`
         )
         .then((d) => {
            setresult(d.data.allPosts);
         })
         .catch((e) => console.log("error"));


   }, [pn, keyword]);

the problem is :

Failed to fetch RSC payload. Falling back to browser navigation. TypeError: Failed to execute ‘fetch’ on ‘Window’: Failed to read the ‘headers’ property from ‘RequestInit’: String contains non ISO-8859-1 code point

the backend url is like this: https://example.com/api/search-posts?keyword=mobile

if I search a English keyword, I have no error but in Persian( like موبایل), This error happens.

thanks…

this error makes the page be refreshed infinite.

2

Answers


  1. Chosen as BEST ANSWER

    escape and unescape worked for me. you can use it if need


  2. Maybe there is an issue with encoding of the non-ASCII characters in your request. It seems like the headers property of the "RequestInit" object is not being read properly because it contains non ISO-8859-1 code points.
    one accessible solution to this could be to encode the Persian keyword using URL encoding and then send it in API .
    In javascript you can use encodeURIComponent(food.title) function.
    Mozilla documentations are useful

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search