codesandbox / codesandbox/codesandbox-client

React editor slows down to become unusable when hot-reloading many images

Open
#7,205 0 comments 1 reaction 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
JavaScript
Stars
13.6k
Forks
2.4k
Avg merge
6d 19h
Merged PRs (30d)
2

Description

🐛 bug report

Preflight Checklist

  • I have read the Contributing Guidelines for this project.
  • I agree to follow the Code of Conduct that this project
    adheres to.
  • I have searched the issue tracker for an issue that matches the one I want
    to file, without success.

Description of the problem

React editor slows down to become unusable when hot-reloading many images

How has this issue affected you? What are you trying to accomplish?

I was using CodeSandbox during an interview for React/TypeScript, where the problem involved displaying many images. When I started generalizing the <img> into its own component, suddenly the editor would say things like "<some variable name I hadn't finished typing> is not defined" (but only when I was working with the "src" parameter) over and over in what looked like an infinite loop of "Problems" with the counter ticking up to the thousands of the same message, slowing down the tab until Chrome let me kill it as "not responding."

Refreshing did not work. I worked around this by copying all the code before the tab slowed down too much, closing it and reopening it. Sometimes, even after closing and reopening, I still had to wait for Chrome to bail out of loading the blank page so I could kill it, which I found odd, and maybe a Chrome-specific thing. I kept trying to turn off hot-reloading, but I couldn't find out how to do this.

To Reproduce

Create a sandbox that tries to fetch ~200 images from different URLs, and trigger re-renders of all the images, by, say, changing the variable name used in the src parameter of the <img> tag. I think the high volume of images fetched contributed to the bug because I wasn't able to reproduce this on a minimal working example.

It also doesn't seem to have any relation to an actual React error - I did, say, cause a standard React "too many re-renders" error with no issues at all, which is what I thought this was at first.

Link to sandbox: link (optional)

This is the exact sandbox I used during the interview, but I've redacted anything that ties this code to the actual interview/company.

Here's a screenshot of what it looks like while the tab slows down. Notice I'm trying to finish typing "src", but the flood of "s is not defined" making the page slow to a crawl isn't letting me do so.

Screen Shot 2022-12-02 at 10 55 49 AM
Your Environment
Software Name/Version
Сodesandbox Reproduced today on 5e842cb16 (as copied from the lower left corner). Noticed yesterday (2022-12-01) but didn't write down the version.
Browser Chrome 107.0.5304.121
Operating System MacOS Monterey 12.5; MacBook Pro M1 (14-inch, 2021)

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with the linked CodeSandbox at src/App.js and reproduce the slowdown using about 200 image URLs and repeated edits to the img src value. Compare the Problems flood and hot-reload behavior before and after the change; done means the editor remains usable without accumulating thousands of repeated diagnostics.

Written by the indexing model from the issue text.

Assessment

Tech stack
javascript, react
Domain
frontend, performance
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.