Skip to content

How do I make a script run only the first time the layout is instantiated and not all subsequent pages (which inherit that layout)? #1930

Description

@frederikhors

Describe the bug

In a new Svelte Kit project I have a <script context="module"> in __layout.svelte.

The load function in it is called on each page I change.

I thought instead it was only called when the layout is instantiated for the first time.

I'm doing it wrong?

How do I make a script run only the first time the layout is instantiated and not all subsequent pages (which inherit that layout)?

Reproduction

https://github.com/frederikhors/issue-svelte-kit-layout-context-module-load-always-called

System Info

System:
    OS: Windows 10 10.0.19043
  Binaries:
    Node: 14.17.3 - C:\Program Files\nodejs\node.EXE
    npm: 7.19.1 - C:\Program Files\nodejs\npm.CMD
  npmPackages:
    @sveltejs/kit: 1.0.0-next.117 => 1.0.0-next.131
    svelte: 3.38.3 => 3.38.3

Severity

annoyance

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Fields

    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions