Comments (2)
Hey @ohitsdoh! 👋 I'm here to help you with bug fixes, answer questions, and guide you on becoming a contributor. Let's squash those bugs together!
To resolve the "Maximum update depth exceeded" error in Apache Superset when loading a dashboard with many filters, you can optimize the useEffect
hooks to depend on more granular information instead of big objects that require deep comparison. This can help prevent unnecessary re-renders and infinite loops.
Here's a revised version of the useEffect
hook with more granular dependencies:
useEffect(() => {
if (!inViewFirstTime) {
return;
}
const newFormData = getFormData({
...filter,
datasetId,
dependencies,
groupby,
adhoc_filters,
time_range,
dashboardId,
});
const filterOwnState = filter.dataMask?.ownState || {};
const customizer = (
objValue: Partial<QueryFormData>,
othValue: Partial<QueryFormData>,
key: string,
) => (key === 'url_params' ? true : undefined);
const formDataChanged = !isEqualWith(formData, newFormData, customizer);
const ownStateChanged = !isEqual(ownState, filterOwnState);
if (!isRefreshing && (formDataChanged || ownStateChanged || shouldRefresh)) {
setFormData(newFormData);
setOwnState(filterOwnState);
if (!hasDataSource) {
return;
}
setIsRefreshing(true);
getChartDataRequest({
formData: newFormData,
force: shouldRefresh,
ownState: filterOwnState,
})
.then(({ response, json }) => {
if (isFeatureEnabled(FeatureFlag.GlobalAsyncQueries)) {
const result = 'result' in json ? json.result[0] : json;
if (response.status === 200) {
setState([result]);
handleFilterLoadFinish();
} else if (response.status === 202) {
waitForAsyncData(result)
.then((asyncResult: ChartDataResponseResult[]) => {
setState(asyncResult);
handleFilterLoadFinish();
})
.catch((error: Response) => {
getClientErrorObject(error).then(clientErrorObject => {
setError(clientErrorObject);
handleFilterLoadFinish();
});
});
} else {
throw new Error(
`Received unexpected response status (${response.status}) while fetching chart data`,
);
}
} else {
setState(json.result);
setError(undefined);
handleFilterLoadFinish();
}
})
.catch((error: Response) => {
getClientErrorObject(error).then(clientErrorObject => {
setError(clientErrorObject);
handleFilterLoadFinish();
});
});
}
}, [
inViewFirstTime,
dependencies.length, // Use length instead of the entire array
datasetId,
groupby,
adhoc_filters.length, // Use length instead of the entire array
time_range,
dashboardId,
handleFilterLoadFinish,
hasDataSource,
isRefreshing,
shouldRefresh,
]);
By using more specific dependencies like dependencies.length
and adhoc_filters.length
, you can reduce the likelihood of unnecessary re-renders and avoid the "Maximum update depth exceeded" error [1].
Additionally, ensure that the applyCharts
method in the Dashboard
component is optimized to avoid unnecessary updates. The applyCharts
method should only trigger updates when there are actual changes in the filters or charts. This can be achieved by comparing the current and previous states of filters and charts using utility functions like areObjectsEqual
.
applyCharts() {
const { hasUnsavedChanges, editMode } = this.props.dashboardState;
const { appliedFilters, appliedOwnDataCharts } = this;
const { activeFilters, ownDataCharts, chartConfiguration } = this.props;
if (
isFeatureEnabled(FeatureFlag.DashboardCrossFilters) &&
!chartConfiguration
) {
// For a first loading we need to wait for cross filters charts data loaded to get all active filters
// for correct comparing of filters to avoid unnecessary requests
return;
}
if (
!editMode &&
(!areObjectsEqual(appliedOwnDataCharts, ownDataCharts, {
ignoreUndefined: true,
}) ||
!areObjectsEqual(appliedFilters, activeFilters, {
ignoreUndefined: true,
}))
) {
this.applyFilters();
}
if (hasUnsavedChanges) {
Dashboard.onBeforeUnload(true);
} else {
Dashboard.onBeforeUnload(false);
}
}
By ensuring that applyCharts
only triggers updates when necessary, you can further reduce the risk of encountering the "Maximum update depth exceeded" error [2].
To continue talking to Dosu, mention @dosu.
from superset.
How many is a lot? Can you reproduce this somehow with example dashboards / datasets?
from superset.
Related Issues (20)
- Docker build it failing - Docker compose up is not working HOT 2
- `show summary` does not correctly apply all filters HOT 2
- Exports are brittle HOT 2
- Superset-4.1.0rc2: Download to CSV option is not showing up in SQL LAB page. HOT 6
- Superset 4.1.0RC2 - New Sankey charts cannot be embedded = "Guest user cannot modify chart payload" HOT 1
- zstd not found by superset_node during docker compose up dev mode HOT 4
- Failed to resolve entry for package "@superset-ui/switchboard". The package may have incorrect main/module/exports specified in its package.json. HOT 2
- SuperSet Database connection is successfully established but not able to get the tables under a specific schema HOT 6
- Annotation formula on chart does not work for values above 1*10^15 (peta) HOT 1
- I'm getting ERROR:flask_migrate:Error while upgrading. HOT 6
- [4.1.0rc2] sqlalchemy InvalidRequestError: This nested transaction is inactive when trying to activate embedding on a dashboard HOT 1
- Superset 4.1 with Pinot not aggregating epoch_ms timestamps correctly HOT 1
- Bangladesh is missing in country map dropdown selection for Country Map Chart HOT 2
- Server Pagination Sort Only Sorts Loaded Rows - Table HOT 1
- Drill-by alert "Failed to load dimensions for drill by" using Gamma role HOT 2
- The end date on the filter panel of the dashboard is failing to capture the current data. HOT 1
- Data Zoom should be fixed scrolling on the dashboard HOT 1
- Bar Chart sorting does not appear to work HOT 2
- DB ERROR HOT 1
- Failed to resolve entry for package @superset-ui/switchboard HOT 5
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from superset.