question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

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

See original GitHub issue

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

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Comments:24 (20 by maintainers)

github_iconTop GitHub Comments

2reactions
kevmodromecommented, Jul 17, 2021

If onMount only runs once I would definitely not expect load to run more than once. Just my 2 cents though.

2reactions
kevmodromecommented, Jul 17, 2021

The way it works feels backwards to me. I wouldn’t expect the layout to be re-mounted when I change pages - I guess that’s the case?

Read more comments on GitHub >

github_iconTop Results From Across the Web

Order of execution for event functions - Unity - Manual
Start : Start is called before the first frame update only if the script instance ... continue after all Update functions have been...
Read more >
How to spawn an object in Unity (using Instantiate)
Learn how to spawn prefabs, create new empty objects & improve performance with object pools, in my in-depth guide to Instantiate in Unity....
Read more >
Layout in ASP.NET Core - Microsoft Learn
This document discusses layouts for the two different approaches to ASP.NET Core MVC: Razor Pages and controllers with views.
Read more >
Class inheritance - The Modern JavaScript Tutorial
The syntax to extend another class is: class Child extends Parent . Let's create class Rabbit that inherits from Animal :.
Read more >
9. Objects, Case Classes, and Traits - Learning Scala [Book]
Instead of creating an instance with a new keyword, just access the object directly by name. An object gets automatically instantiated the first...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found