Skip to content
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

TypeError: Cannot read properties of undefined (reading 'swapStyle') #43

Open
aral opened this issue Mar 13, 2024 · 1 comment
Open

Comments

@aral
Copy link

aral commented Mar 13, 2024

I’m getting the following error when using idiomorph with htmx-ws:

htmx-1.js:1899 TypeError: Cannot read properties of undefined (reading 'swapStyle')
    at Object.isInlineSwap (htmx-idiomorph-0.3.js:863:27)
    at isInlineSwap (htmx-1.js:695:35)
    at htmx-1.js:733:30
    at forEach (htmx-1.js:369:21)
    at Object.oobSwap (htmx-1.js:726:17)
    at WebSocket.<anonymous> (htmx-ws-1.js:148:10)

The referenced point in htmx is:

        function isInlineSwap(swapStyle, target) {
            var extensions = getExtensions(target);
            for (var i = 0; i < extensions.length; i++) {
                var extension = extensions[i];
                try {
                    if (extension.isInlineSwap(swapStyle)) {
                        return true;
                    }
                } catch(e) {
                    logError(e);
                }
            }
            return swapStyle === "outerHTML";
        }

And the place in idiomorph is:

    htmx.defineExtension('morph', {
        isInlineSwap: function(swapStyle) {
            let config = createMorphConfig(swapStyle);
            return config.swapStyle === "outerHTML" || config.swapStyle == null;
        },
        handleSwap: function (swapStyle, target, fragment) {
            let config = createMorphConfig(swapStyle);
            if (config) {
                return Idiomorph.morph(target, fragment.children, config);
            }
        }
    });

If I can narrow it down further, I’ll update the issue.

@th3l0g4n
Copy link

I had the same issue after switching to idiomorph.
Have a look at #24 (comment).
This fixed the error in my case.

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

No branches or pull requests

2 participants