Skip to content

TypeError: (intermediate value) is not iterable #195

@dong-sir

Description

@dong-sir

Describe the bug

Follow the compiledCache option in docx/examples.md

compiledCache: {
    set(key, str) {

        // naive storage space management
        for (; ;) {

            try {

                // doc: https://developer.mozilla.org/en-US/docs/Web/API/Storage
                window.localStorage.setItem(key, str);
                break;
            } catch (ex) {

                // handle: Uncaught DOMException: Failed to execute 'setItem' on 'Storage': Setting the value of 'XXX' exceeded the quota

                window.localStorage.removeItem(window.localStorage.key(0));
            }
        }
    },
    get(key) {

        return window.localStorage.getItem(key);
    },
},

To Reproduce

<html>

<body>
    <div id="app"></div>
    <script src="https://unpkg.com/vue@latest"></script>
    <script src="https://cdn.jsdelivr.net/npm/vue3-sfc-loader/dist/vue3-sfc-loader.js"></script>
    <script>

        const options = {
            moduleCache: {
                vue: Vue
            },
            async getFile(url) {

                const res = await fetch(url);
                if (!res.ok)
                    throw Object.assign(new Error(res.statusText + ' ' + url), { res });
                return {
                    getContentData: asBinary => asBinary ? res.arrayBuffer() : res.text(),
                }
            },
            addStyle(textContent) {

                const style = Object.assign(document.createElement('style'), { textContent });
                const ref = document.head.getElementsByTagName('style')[0] || null;
                document.head.insertBefore(style, ref);
            },
            compiledCache: {
                set(key, str) {

                    // naive storage space management
                    for (; ;) {

                        try {

                            // doc: https://developer.mozilla.org/en-US/docs/Web/API/Storage
                            window.localStorage.setItem(key, str);
                            break;
                        } catch (ex) {

                            // handle: Uncaught DOMException: Failed to execute 'setItem' on 'Storage': Setting the value of 'XXX' exceeded the quota

                            window.localStorage.removeItem(window.localStorage.key(0));
                        }
                    }
                },
                get(key) {

                    return window.localStorage.getItem(key);
                },
            },
        }

        const { loadModule } = window['vue3-sfc-loader'];

        const app = Vue.createApp({
            components: {
                'my-component': Vue.defineAsyncComponent(() => loadModule('./myComponent.vue', options))
            },
            template: '<my-component></my-component>'
        });

        app.mount('#app');

    </script>
</body>

</html>

Expected behavior

Versions

  • Browser (name & version): Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/126.0.0.0 Safari/537.36
  • vue3-sfc-loader: https://cdn.jsdelivr.net/npm/vue3-sfc-loader/dist/vue3-sfc-loader.js

Additional context

Here's where the problem might be.

if ( valueStr !== undefined )

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions