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

Uncaught TypeError: y.fragment.l is not a function #2901

Closed
erichui opened this issue May 29, 2019 · 14 comments
Closed

Uncaught TypeError: y.fragment.l is not a function #2901

erichui opened this issue May 29, 2019 · 14 comments
Labels
awaiting submitter needs a reproduction, or clarification

Comments

@erichui
Copy link

erichui commented May 29, 2019

No description provided.

@erichui
Copy link
Author

erichui commented May 29, 2019

There is no l method in the object that the create_fragment method puts back
21_00_24__05_29_2019

@Conduitry
Copy link
Member

Please give a small component that reproduces this.

@Conduitry
Copy link
Member

Conduitry commented May 29, 2019

The l method is used in claiming nodes during hydration. Are you attempting to use hydration without compiling with hydratable: true?

@Conduitry Conduitry added the awaiting submitter needs a reproduction, or clarification label May 29, 2019
@Conduitry
Copy link
Member

Please reopen if you have a repro and the issue isn't that you are hydrating without compiling with it enabled.

@erichui
Copy link
Author

erichui commented Jun 5, 2019

The l method is used in claiming nodes during hydration. Are you attempting to use hydration without compiling with hydratable: true?

First of all, thanks. I forgot to turn it on when compiling

@matthewmueller
Copy link

matthewmueller commented Mar 25, 2020

This took me awhile to figure this out. To perhaps save other folks some time, for SSR there are 3 considerations:

1. Rendering HTML

svelte.compile(code, {
  filename: "...",
  generate: 'ssr'
})

You do not need hydratable here.

2. Compile the client

svelte.compile(code, {
  filename: "...",
  generate: 'dom',
  hydratable: true
})

You do need hydratable here.

3. Render the client

App.render({
  target: document.body,
  hydrate: true
}) 

You do need hydrate here.


It makes perfect sense now, but the error is a bit terse and it seemed like a Svelte bug.

@Losses
Copy link

Losses commented Aug 23, 2020

@Conduitry Maybe the detailed tutorial of ssr with Svelte should be an independent chapter on the official document?

@PierBover
Copy link

PierBover commented Sep 10, 2020

It makes perfect sense now, but the error is a bit terse and it seemed like a Svelte bug.

hydratable sounds like the component should output hydratable HTML, or that it can be hydrated, so it's weird that it's an option for the client side component.

Anyway thanks for the tip @matthewmueller !

@arackaf
Copy link
Contributor

arackaf commented Nov 17, 2020

To add onto what matthewmueller said, hydratable is something you need to add to your webpack config, so Svelte compiles something that can be consumed SSR.

I think this is an area where some better error messages might help.

@vish01
Copy link

vish01 commented Jul 15, 2021

I'm passing in hydratable:true when compiling svelte component, still getting error mentioned in this issue. I was trying to debug on the client side and this is what I've found:
image
l() is not available inside c.fragment.

@PierBover
Copy link

@vish01 are you using hydratable when compiling the client or the server component?

This option is only for compiling the client-side component that will hydrate the server-rendered HTML.

If you're hydrating, you also need to set hydrate: true when instantiating the component client-side.

@vish01
Copy link

vish01 commented Jul 15, 2021

@PierBover I'm using hydratable when compiling a server component. And I'm using hydrate: true when I instantiate component too:
A quick example:

<script type="module">
    export const load = async ({ fetch, page }) => {
        var CompFinal = await import('./testAsset.svelte').default;
        return {
                props: { CompFinal: CompFinal },
            };
}
</script>

<script>
import { onMount } from 'svelte';
    export let CompFinal;
    onMount(() => {
        const executed = new CompFinal({
            target: document.body,
            hydrate: true
        });
        console.log('Executed?', executed);
    });
</script>

Let me know if I'm doing something wrong. I'm not an expert at this haha.

@PierBover
Copy link

@vish01 like I said, the hydratable setting is when compiling the client-side component.

See this comment just above: #2901 (comment)

@vish01
Copy link

vish01 commented Jul 15, 2021

@PierBover Sorry I forgot to mention that I'm importing the component on the client side in a different way. I'm fetching a svelte component from another server like this:

export const load = async ({ fetch, page }) => {
        var renderedContent = {};
        const response = await fetch(`url-to-endpoint`)
        if (response.ok) {
            renderedContent = await response.json();
            //store svelte code to a .svelte file
           fs.writeFileSync('src/routes/temp2/testAsset.svelte', renderedContent.asset, 'utf8');
           var CompFinal = await import('./testAsset.svelte').default;
           }
//the rest of the code follows...

Isn't this considered as client side hydrating? Since I'm importing a svelte component at the client side.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
awaiting submitter needs a reproduction, or clarification
Projects
None yet
Development

No branches or pull requests

7 participants