SAP / ui5-webcomponents-react

A wrapper implementation for React of the UI5 Web Components that are compliant with the SAP Fiori User Experience
https://sap.github.io/ui5-webcomponents-react/
Apache License 2.0
446 stars 101 forks source link

[v1] StyleStore leaks memory #6646

Closed ej612 closed 11 hours ago

ej612 commented 15 hours ago

Describe the bug

Hi there,

My sincere apologies for bugging you with an issue with v1, but we're still stuck on it unfortunately.

I'm in the process of updating our project from 1.26.2 to 1.29.13 and I can't get our test suite to pass since Chrome crashes due to running out of memory (Chrome seems to have a hardcoded memory cap at 4.4GB). I have managed to track the issue down to the cleanup function of @ui5/webcomponents-react-base/dist/stores/StyleStore:

function subscribe(listener) {
    const listeners = getListeners();
    STORE_LOCATION[getStyleStoreListenersSymbol()] = [...listeners, listener];
    return () => {
        // vvvvv
        STORE_LOCATION[getStyleStoreListenersSymbol()] = listeners.filter((l) => l !== listener);
        // ^^^^^
    };
}

It seems like listeners is not properly torn down and leftover listeners accumulate over time: image

Here's the corresponding entry in the JS heap snapshot: image

I seem to have managed to make the tests pass by changing the cleanup to:

STORE_LOCATION[getStyleStoreListenersSymbol()] = [];

But I don't know if this is too brusque.

Thanks a lot in advance!

UI5 Web Components for React Version

1.29.13

UI5 Web Components Version

1.24.13

Browser

Chrome