hperrin / svelte-material-ui

Svelte Material UI Components
https://sveltematerialui.com/
Apache License 2.0
3.33k stars 285 forks source link

Crash in List/Item.Svelte - element.getElement is not a function #599

Open mkyral opened 1 year ago

mkyral commented 1 year ago

Describe the bug In some cases, returning to previously loaded page, I'm getting following crash:

Uncaught (in promise) TypeError: element.getElement is not a function
    1b Item.svelte:128
    run index.mjs:20
    mount_component index.mjs:2101
    flush index.mjs:1329
    promise callback*schedule_update index.mjs:1258
    make_dirty index.mjs:2133
    ctx index.mjs:2171
    removeClass bundle.js:76129
    setUnbounded foundation.js:183
    handleProps Ripple.js:70
    promise callback*handleProps Ripple.js:67
    Ripple Ripple.js:99
    useActions useActions.js:8
    mount bundle.js:5778
    mount bundle.js:5631
...

Probably introduced by commit 73fe3dfcbd26089e77765bf83196217958a206c5 It's curious that in previous commit d617f9727ab23fdf7662659e2332534d8009ee26 was added check to ensure that element is not null. But this check was not included in move into onMount() function.

mkyral commented 1 year ago

It is caused by Autocomplete. When I enter screen first time, there is a delay caused by downloading data from server. But when I enter screen for second time, data are already downloaded and it crashes on undefined getElement function.

Note: I'm using {#key} to force Autocomplete element refresh on list change.

{#key suppliersListUpdated}
    <Autocomplete
        options="{() => {return [...suppliersList]}}"
        bind:value={supplierFilter}
        deleteBtnEnabled={true}
        getOptionLabel="{(option) => option ? `${option.supplierNo} - ${option.supplierName}` : ''}"
        label="{$_('supplier')}"
        textfield$class="white small"
        textfield$variant="outlined"
    />
{/key}

After some investigation I've updated the key calculation to ensure that Array is defined and is not empty and it fixed the issue. But I still have no idea what exactly was wrong.

hperrin commented 8 months ago

Is this still an issue in the latest version?