Skip to content

[BUG] Weird component redraw issue in dash 2.16 #2775

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

Closed
CNFeffery opened this issue Mar 2, 2024 · 2 comments
Closed

[BUG] Weird component redraw issue in dash 2.16 #2775

CNFeffery opened this issue Mar 2, 2024 · 2 comments
Assignees

Comments

@CNFeffery
Copy link
Contributor

Consider the following demo component:

import { useEffect } from 'react';
import PropTypes from 'prop-types';

const DemoComponent = (props) => {

    useEffect(() => {
        console.log('========================')
        console.log('DemoComponent is redrawning');
    })

    return <div >DemoComponent</div>;
}

DemoComponent.propTypes = {
    /**
     * Component id.
     */
    id: PropTypes.string,

    loading_state: PropTypes.shape({
        /**
         * Determines if the component is loading or not
         */
        is_loading: PropTypes.bool,
        /**
         * Holds which property is loading
         */
        prop_name: PropTypes.string,
        /**
         * Holds the name of the component that is loading
         */
        component_name: PropTypes.string
    }),

    /**
     * Dash-assigned callback that should be called to report property changes
     * to Dash, to make them available for callbacks.
     */
    setProps: PropTypes.func
};

DemoComponent.defaultProps = {
}

export default DemoComponent;

In the following case, useEffect is executed a lot more times in 2.16 than 2.15:

app.layout = html.Div(
    [
        'Dash: '+dash.__version__,
        html.Br(),
        html.Button('test', id='input'),
        html.Div(
            DemoComponent(),
            id='output'
        )
    ],
    style={
        'padding': 50
    }
)


@app.callback(
    Output('output', 'children'),
    Input('input', 'n_clicks'),
    prevent_initial_call=True
)
def demo(n_clicks):

    return DemoComponent()


if __name__ == '__main__':
    app.run(debug=True)

in 2.15:

demo215

in 2.16:

demo216

@T4rk1n @alexcjohnson

@T4rk1n
Copy link
Contributor

T4rk1n commented Mar 4, 2024

Thanks for the report, I was able to identify the cause, I'll have a fix soon and add a test for redraws.

@T4rk1n T4rk1n self-assigned this Mar 4, 2024
@CNFeffery
Copy link
Contributor Author

The problem has been solved👍.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants