Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Next.JS app freezing in browser when adding an input field

I’m using Next.JS to build a form. I have two inputs and I have used the general react way of reading and validating text in the input.

"use client"
import { firebaseApp } from '@/app/firebase';
import React, { useCallback, useEffect, useState } from 'react'
import { collection, getDocs, getFirestore } from "firebase/firestore";

export default async function skills() {
    const [title, settitle] = useState("");
    const [tags, setTags] = useState("");
 
  return (
    <div>
        <form >
            <input type="text" name='title' id="title" placeholder='title'/>
            <input type="text" name='tags' id="tags" placeholder='tags(, seperated)' value={tags} onChange={e=>setTags(e.target.value)} />
            <button>+</button>
        </form>
    </div>
  )
}

I have tried this code on Brave and Chrome and it freezes the page on both. The page freezes so hard that even the dev tools stop resoponding. I have a feeling it might be linked to some sort of memory leak but I cannot be sure.

I thought that this could be an issue with the way I’ve implemented the login using firebase auth but even bypassing that this code freezes.

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

This is my first time using Next.JS and I’m not sure what could be causing this.

Edit: I was able to gather a preview of the performance recording
The Performance snapshot

I think the onChange is causing multiple re-renders maybe, I see the minor GC kicking in so maybe the onChange listener is not properly set up. I’m not so sure.

The last part where the memory has an erratic spike pattern is when I started adding values to the tags field.

>Solution :

You need to remove the async keyword from your client component. Async components are supported only on the server.

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading