ishaan1013 / sandbox

A cloud-based code editing environment with an AI copilot and real-time collaboration
MIT License
1.25k stars 95 forks source link

fix: Using editor results in thousands of socket XHR requests, added debounce function for the editor #33

Closed Akhileshrangani4 closed 2 days ago

Akhileshrangani4 commented 3 weeks ago

Code was creating a new socket connection every time the CodeEditor component is mounted.

Now, the socket connection is created only once and reused. I've used a ref to store the socket instance and only create the connection if it doesn't already exist.

it was mentioned before in #13 that this was happening and while I was using it locally, Cloudflare was up to 35k requests in a short amount of time.

I also added a debounce function for the editor.