Skip to content

Component that changes a sub-property of its own state object by async method re-renders the whole component in an infinite loop #98

@Clonkex

Description

@Clonkex

This one is quite confusing. I'm not sure if I'm doing something wrong or if it's a bug in ArrowJS.

This is as simple as I can make it while still replicating the behaviour:

https://jsfiddle.net/9d51qhe2

<script type="module">
    import { reactive, html } from 'https://esm.sh/@arrow-js/core';

    const main = getMain();
    main(document.querySelector('#container'));

    function getMain() {
        return html`
            <div>
                ${() => html`
                    ${() => console.log('zz0mkno')}
                    ${getLoginComponent()}
                `}
            </div>
        `;
    }

    function getLoginComponent() {
        const state = reactive({
            pageDatas: [],
        });
        setTimeout(async () => {
            state.pageDatas.push(Date.now());
        }, 500);

        return html`<div>bob</div>`;
    }
</script>

<div id="container">
</div>

If you run the fiddle, you'll see it continually prints zz0mkno. It's re-rendering the entire getLoginComponent component every time in an infinite loop.

Here's a fiddle that demonstrates more closely what I was doing when I came across this bug (including a network request instead of a timeout). Basically I was loading some user data on the login page to allow it to do client-side validation before making a server request to log in.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions