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 issueDescribe 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:
- Created 2 years ago
- Comments:24 (20 by maintainers)
Top 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 >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
If onMount only runs once I would definitely not expect load to run more than once. Just my 2 cents though.
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?