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

svelte:head repeated in SSR possibly due to bindings/$$settled logic #4982

Closed
gushogg-blake opened this issue Jun 6, 2020 · 4 comments · Fixed by #9124
Closed

svelte:head repeated in SSR possibly due to bindings/$$settled logic #4982

gushogg-blake opened this issue Jun 6, 2020 · 4 comments · Fixed by #9124
Labels
compiler Changes relating to the compiler stale-bot temp-stale

Comments

@gushogg-blake
Copy link

I haven't been able to create a simple repro for this unfortunately.

Tags inside <svelte:head> are being repeated in SSR output so any scripts defined there are getting loaded twice, e.g.:

<head>
    <script src="/script.js"></script>
    <script src="/script.js"></script>
</head>

A console.trace from the top-level <script> of the component that has the <svelte:head> block indicates that that component is being "called" twice also. The trace stack leads to a do-while loop in the callback passed to internal.create_ssr_component, which seems to be implementing logic for repeatedly rendering components until the values of bound props are resolved ($$settled).

The code that directly causes the repetition seems to be $$result.head += ... added by src/compiler/compile/render_ssr/handlers/Head.ts.

@tommywalkie
Copy link

tommywalkie commented Sep 21, 2020

Made a repo (svelte-head-ssr-dupe-repro) using the default Sapper template for reproducing the issue.

In src/routes/index.svelte I just added the following code :

<script>
    let filename
    const getCurrentFile = input => {
        const split = input.split(/[\\/]/)
        return split.splice(split.length - 2, split.length).join('/')
    }
    try {
        // Should output `server/server.js` if run inside Node
        filename = getCurrentFile(__filename)
    } catch (error) {
        // Should output something like `client/client.c11ed98a.js` if run inside browser
        filename = getCurrentFile(document.scripts[document.scripts.length-1].src)
    }
    const style = `<style location="${filename}">p { color: blue; }</style>`
</script>

<svelte:head>
    <title>Sapper project template</title>
    {@html style}
</svelte:head>

When running the Sapper dev server, this is the following output in <head> section :

<style location="server/server.js">p { color: blue; }</style>
<style location="client/client.4cce6104.js">p { color: blue; }</style>

@mattpilott
Copy link
Contributor

Im seeing this too when i do:

<svelte:head>
  {@html page.yoast_head}
</svelte:head>

@stale
Copy link

stale bot commented Jun 26, 2021

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

@stale stale bot added the stale-bot label Jun 26, 2021
@pngwn pngwn added the compiler Changes relating to the compiler label Jun 26, 2021
@stale stale bot removed the stale-bot label Jun 26, 2021
@stale stale bot removed the stale-bot label Jun 26, 2021
@stale stale bot removed the stale-bot label Jun 27, 2021
@stale
Copy link

stale bot commented Dec 24, 2021

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
compiler Changes relating to the compiler stale-bot temp-stale
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants