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

Button issue - le is undefined when links followed #18

Open
rohfle opened this issue Aug 6, 2019 · 5 comments
Open

Button issue - le is undefined when links followed #18

rohfle opened this issue Aug 6, 2019 · 5 comments
Assignees
Labels
bug Something isn't working

Comments

@rohfle
Copy link

rohfle commented Aug 6, 2019

Hello,

Summary

I am using svelma and svelte-spa-router for a project and I am having an issue where having a svelma button on a page will cause the page to error when links are followed.

POC

Here is an example project that reproduces the issue: https://github.com/rohfle/svelma-button-issue-poc

Details

When I import using import { Button } from 'svelma', I get the following error when I click a link to take me to another page:

TypeError: le is undefined [module.js:1:4169]

console.log(Button) gives me:
image

When I import using import Button from 'svelma/src/components/Button.svelte', I get no error and console.log(Button) gives me:
image

@rohfle rohfle changed the title Button issue - le is undefined Button issue - le is undefined when links followed Aug 6, 2019
@c0bra
Copy link
Owner

c0bra commented Aug 12, 2019

Looking into it; thanks for the repro repo.

@c0bra c0bra self-assigned this Aug 12, 2019
@c0bra c0bra added the bug Something isn't working label Aug 12, 2019
@c0bra
Copy link
Owner

c0bra commented Aug 12, 2019

I think this may be fixed by this: sveltejs/svelte#3159 It fixed the docs navigation bug. Going to try.

Update 1: Not fixed, furthermore when I npm link uncompiled Svelma I get the error on both the import types you did.

Update 2: The errors I'm seeing with unminified source point to issues with transition outros being undefined. My hunch is that this is related to sveltejs/svelte#3166 and svelte-spa-router needs to update their version of Svelte.

@c0bra
Copy link
Owner

c0bra commented Sep 5, 2019

@rohfle Looks like it's still happening with svelte-spa-router >= 1.2.0

@josh-richardson
Copy link

I'm also getting this with svelte-spa-router 1.2.0 and svelma 0.3.

@rohfle
Copy link
Author

rohfle commented Nov 6, 2019

So I dug into this a little bit more because it puzzled me:

Console trace

image

Relevant code

    let outros$1;
    function group_outros$1() {
        outros$1 = {
            r: 0,
            c: [],
            p: outros$1 // parent group
        };
        console.log('group_outros$1', outros$1)
    }
    function check_outros$1() {
        if (!outros$1.r) {
            run_all$1(outros$1.c);
        }

        outros$1 = outros$1.p;
        console.log('check_outros$1', outros$1)
    }
    function transition_in$1(block, local) {
        if (block && block.i) {
            outroing$1.delete(block);
            block.i(local);
        }
    }
    function transition_out$1(block, local, detach, callback) {
        console.log('transition_out$1', outros$1, 'block', block)
        if (block && block.o) {
            if (outroing$1.has(block))
                return;
            outroing$1.add(block);
            outros$1.c.push(() => {      // THIS IS WHERE THE ERROR HAPPENS
                outroing$1.delete(block);
                if (callback) {
                    if (detach)
                        block.d(1);
                    callback();
                }
            });
            block.o(local);
        }
    }

Notes

  • There are two transition_out functions in the repro repo bundle.js - transition_out and transition_out$1 (part of the Svelma module.js bundle)
  • Where the error happens, outros$1 is undefined.
  • The normal calling pattern is
group_outros(); // creates a outros object with existing outros as parent
transition_out(); // calls a blocks outro function 
   b1.o() // outros function for block if there is one
check_outros(); // makes outros parent the outros object
  • The calling pattern we are seeing with the bug is
group_outros();
transition_out();
   b1.o(); // outros function for block b1
     group_outros();
     transition_out(); // this one is ok
     transition_out();
       b2.o(); // outros function for sub block b2
         // group_outros$1() is not called
         transition_out$1(); // this is where the error happens for block b3
         // check_outros$1() is not called
     check_outros(); // code never gets here
check_outros()

It seems there are two different sveltes running with different transition functions and global variables - one that is part of the repro repo and one that is part of the svelma bundle. Could this be why the issue is occurring? I tried compiling Svelma from source using rollup with terser turned off. The above naming with $1s are renames automatically performed by rollup to prevent name conflict. On the minified code it just has random functions, but they are still distinct from the repro repo ones.

Note that svelte-spa-router is just raw .svelte code that gets imported by the repro repo. Perhaps svelma has to switch to using the same thing? (Use svelte straight from source, not precompiled)

EDIT: similar to issue #29 - kroshilin's proposed PR #31 fixes the issue in the repro repo successfully!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

3 participants