React rendering is completely hanging the firefox

Environment

  • Surface: Web
  • Browser or app version: stable Firefox 157.0
  • Affected feature and model, if relevant: Chat

Bug

Start any chat in Firefox; any 2-3 page-long conversation is hanging the web browser completely. You can’t even normally put a message into the textarea and send it. You can’t normally scroll the conversation.

Reproduction

Start any conversation and do 2-3 pages. Just ask some questions about the weather, and that’s enough. After that, try to change the focus from the main text to the textarea.

You won’t be able to put a new message until the React engine re-renders all components many times. So it will be possible for you to input a new message only after 3-5 seconds.

The same thing happens when you are trying to press the send button after you are done with a new message and want to send it. The click on the send button also triggers the focus, and it triggers re-renders of the whole website. So you have to wait for 3-5 seconds until your button will actually work.

The same thing happens when you are trying to scroll the page. The web browser is hanging, trying to do unnecessary renderings. It may hang for 3-5 seconds.

This bug is not about the long conversation; this bug is about any-sized conversation and broken React rendering.

Diagnostics

Find the current container with the class [container-name:thread-content] in the dev tools and click on it. After that, switch to the console and launch the code.

(() => {
    const element = $0;

    if (!(element instanceof Element)) {
        throw new Error("Select an element in DevTools first");
    }

    let domUpdates = 0;
    let mutations = 0;
    let reactCommits = 0;

    const started = performance.now();

    // Monitor DOM updates inside the selected element
    const observer = new MutationObserver((records) => {
        domUpdates++;
        mutations += records.length;

        const elapsed = (performance.now() - started).toFixed(1);

        console.log(
            `[BLOCK UPDATE #${domUpdates}]`,
            `${elapsed}ms`,
            `${records.length} mutations`,
            records.map(r => ({
                type: r.type,
                attribute: r.attributeName,
                target: r.target
            }))
        );
    });

    observer.observe(element, {
        subtree: true,
        childList: true,
        characterData: true,
        attributes: true
    });

    // Count React commits across the page
    const hook = window.__REACT_DEVTOOLS_GLOBAL_HOOK__;
    const original = hook?.onCommitFiberRoot;

    let wrapped;

    if (typeof original === "function") {
        wrapped = function (...args) {
            reactCommits++;
            return original.apply(this, args);
        };

        hook.onCommitFiberRoot = wrapped;
    }

    // Report every second
    const interval = setInterval(() => {
        console.log(
            `[STATS] DOM updates: ${domUpdates}` +
            ` | Mutations: ${mutations}` +
            ` | React commits: ${reactCommits}`
        );
    }, 1000);

    window.stopBlockWatch = () => {
        observer.disconnect();
        clearInterval(interval);

        if (hook?.onCommitFiberRoot === wrapped) {
            hook.onCommitFiberRoot = original;
        }

        console.table({
            domUpdateBatches: domUpdates,
            domMutations: mutations,
            pageReactCommits: reactCommits,
            durationSeconds:
                ((performance.now() - started) / 1000).toFixed(1)
        });
    };

    console.log("Monitoring selected block:", element);
    console.log("Stop using stopBlockWatch()");
})();

After that, try to input some text and try to send it. Also, try to scroll the page. You will see an enormous amount of useless renders like:

[STATS] DOM updates: 12 | Mutations: 31 | React commits: 25

Also try to use Firefox profiler:

You can see the massive cumulative rendering overhead.

Please ask any frontend developer to launch Firefox and try to debug basic functions like the main textarea and send button.

Personally, I am 100% sure that some state, props, etc. is triggering useless re-rendering; it is a classical intern/junior/vibe-coding issue.

I don’t know why this issue is critical for Firefox only, because Chrome is also doing the same useless renderings, and the code is the same in different browsers. Maybe the Blink engine just eats useless renderings much more effectively than Gecko.

This issue persists for more than 1 year. Can you please address it? Thank you.