Skip to content

Adjusting memoization on the DashWrapper to be utilized #3248

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 34 commits into from
Apr 1, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
34 commits
Select commit Hold shift + click to select a range
393e870
Adjusting memoization on the `DashWrapper` to be utilized
BSd3v Mar 26, 2025
3c2898d
adjusting hash for renders
BSd3v Mar 26, 2025
25c20de
simplifying and using the reducer to trigger adjustments only if the …
BSd3v Mar 27, 2025
dc2e2bd
making json stringify simpler to keep from circular references
BSd3v Mar 27, 2025
adbb030
testing internal `setProps` to make sure the component is still in th…
BSd3v Mar 27, 2025
b77e7b7
fixing issue with `set_progress` not triggering properly when needing…
BSd3v Mar 27, 2025
5eed5fe
refactor for `dashWrapper` made the `reducer` recursive to get the ne…
BSd3v Mar 27, 2025
02bf1c8
reverting to using memo, but only memoizing on the hash
BSd3v Mar 28, 2025
cbc93b9
adjustments for how children are added when the prop was changed
BSd3v Mar 28, 2025
8ae3b22
adding support for sending hashes to components as props
BSd3v Mar 28, 2025
5c505e9
adjusting children for rerendering
BSd3v Mar 28, 2025
3d4ec1d
adding changelog entry
BSd3v Mar 28, 2025
c772126
updated wrapper to pass new props down to the components upon a new r…
BSd3v Mar 29, 2025
62ec2ac
adding ignore for unused var
BSd3v Mar 29, 2025
197901a
swapped hash with actual item and props
BSd3v Mar 29, 2025
e2f89e9
adjustments for lint
BSd3v Mar 29, 2025
8862956
updated patch test to use until instead of assert to allow timing flux
BSd3v Mar 29, 2025
3bc85d3
fixing for lint
BSd3v Mar 29, 2025
5c6dbc3
adjusting to only render children components as 'new' if it is a new …
BSd3v Mar 31, 2025
889b4a5
removed the new prop being passed down: `rendertype`
BSd3v Mar 31, 2025
9c8a62a
adding `renderType` but making it a conditional prop that the compone…
BSd3v Mar 31, 2025
ef41561
adding test component and test for rendertype prop
BSd3v Mar 31, 2025
c409895
removing unused import
BSd3v Mar 31, 2025
bf00422
Merge remote-tracking branch 'remote/dev' into performance-adjust
BSd3v Mar 31, 2025
ce1da9a
adjusting `renderType` to `dashRenderType` if the dev wants to subscr…
BSd3v Mar 31, 2025
f0db8c5
replacing `Date.now()` with new object to force rerender
BSd3v Mar 31, 2025
6588aac
adjusting for lint
BSd3v Mar 31, 2025
5e1bdf3
adjustments from feedback
BSd3v Mar 31, 2025
96166c8
adjusting for `state` no longer needed in dispatch
BSd3v Apr 1, 2025
3ade208
adjustments based on feedback
BSd3v Apr 1, 2025
6f744f0
reverting errant adjustment
BSd3v Apr 1, 2025
04fc346
additional `component` -> `renderComponent` adjustments
BSd3v Apr 1, 2025
0dea738
adjusting for missing variable swaps and removing unused `memoizeProps`
BSd3v Apr 1, 2025
cde9acf
updating change log entry
BSd3v Apr 1, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 23 additions & 0 deletions @plotly/dash-test-components/src/components/RenderType.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
import React, { useState, useEffect } from "react";
import PropTypes from "prop-types";

const RenderType = (props) => {
const onClick = () => {
props.setProps({n_clicks: (props.n_clicks || 0) + 1})
}

return <div id={props.id}>
<span>{props.dashRenderType}</span>
<button onClick={onClick}>Test Internal</button>
</div>;
};

RenderType.propTypes = {
id: PropTypes.string,
dashRenderType: PropTypes.string,
n_clicks: PropTypes.number,
setProps: PropTypes.func
};

RenderType.dashRenderType = true;
export default RenderType;
2 changes: 2 additions & 0 deletions @plotly/dash-test-components/src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import MyPersistedComponentNested from './components/MyPersistedComponentNested'
import StyledComponent from './components/StyledComponent';
import WidthComponent from './components/WidthComponent';
import ComponentAsProp from './components/ComponentAsProp';
import RenderType from './components/RenderType';

import DrawCounter from './components/DrawCounter';
import AddPropsComponent from "./components/AddPropsComponent";
Expand All @@ -32,4 +33,5 @@ export {
ShapeOrExactKeepOrderComponent,
ArrayOfExactOrShapeWithNodePropAssignNone,
ExternalComponent,
RenderType
};
7 changes: 7 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,17 @@ This project adheres to [Semantic Versioning](https://semver.org/).

## Changed
- [#3113](https://github.com/plotly/dash/pull/3113) Adjusted background polling requests to strip the data from the request, this allows for context to flow as normal. This addresses issue [#3111](https://github.com/plotly/dash/pull/3111)
- [#3248](https://github.com/plotly/dash/pull/3248) Changes to rendering logic:
- if it is first time rendering, render from the parent props
- listens only to updates for that single component, no children listening to parents
- if parents change a prop with components as props, only the prop changed re-renders, this is then forced on all children regardless of whether or not the props changed

## Fixed
- [#3251](https://github.com/plotly/dash/pull/3251). Prevented default styles from overriding `className_*` props in `dcc.Upload` component.

## Added
- [#3248](https://github.com/plotly/dash/pull/3248) added new `dashRenderType` to determine why the component layout was changed (`internal`, `callback`, `parent`, `clientsideApi`):
- this can be utilized to keep from rendering components by the component having `dashRenderType` defined as a prop, and the `dashRenderType = true` must be set on the component, eg (`Div.dashRenderType = true`)

## [3.0.1] - 2025-03-24

Expand Down
3 changes: 2 additions & 1 deletion dash/dash-renderer/src/actions/callbacks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -360,7 +360,8 @@ function updateComponent(component_id: any, props: any, cb: ICallbackPayload) {
dispatch(
updateProps({
props,
itempath: componentPath
itempath: componentPath,
renderType: 'callback'
})
);
dispatch(notifyObservers({id: component_id, props}));
Expand Down
4 changes: 2 additions & 2 deletions dash/dash-renderer/src/observers/executedCallbacks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -63,12 +63,12 @@ const observer: IStoreObserverDefinition<IStoreState> = {
// In case the update contains whole components, see if any of
// those components have props to update to persist user edits.
const {props} = applyPersistence({props: updatedProps}, dispatch);

dispatch(
updateProps({
itempath,
props,
source: 'response'
source: 'response',
renderType: 'callback'
})
);

Expand Down
19 changes: 14 additions & 5 deletions dash/dash-renderer/src/reducers/reducer.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ export const apiRequests = [
'loginRequest'
];

function layoutHashes(state = {}, action) {
const layoutHashes = (state = {}, action) => {
if (
includes(action.type, [
'UNDO_PROP_CHANGE',
Expand All @@ -37,12 +37,21 @@ function layoutHashes(state = {}, action) {
) {
// Let us compare the paths sums to get updates without triggering
// render on the parent containers.
const strPath = stringifyPath(action.payload.itempath);
const prev = pathOr(0, [strPath], state);
return assoc(strPath, prev + 1, state);
const actionPath = action.payload.itempath;
const strPath = stringifyPath(actionPath);
const prev = pathOr(0, [strPath, 'hash'], state);
state = assoc(
strPath,
{
hash: prev + 1,
changedProps: action.payload.props,
renderType: action.payload.renderType
},
state
);
}
return state;
}
};

function mainReducer() {
const parts = {
Expand Down
5 changes: 3 additions & 2 deletions dash/dash-renderer/src/utils/clientsideFunctions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,16 +16,17 @@ function set_props(
for (let y = 0; y < ds.length; y++) {
const {dispatch, getState} = ds[y];
let componentPath;
const {paths} = getState();
if (!Array.isArray(idOrPath)) {
const {paths} = getState();
componentPath = getPath(paths, idOrPath);
} else {
componentPath = idOrPath;
}
dispatch(
updateProps({
props,
itempath: componentPath
itempath: componentPath,
renderType: 'clientsideApi'
})
);
dispatch(notifyObservers({id: idOrPath, props}));
Expand Down
Loading