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.

Ability to override load or use before/after hooks

See original GitHub issue

One of the most common requests in Sapper is a way to alter fetch or otherwise affect the load calls

Is your feature request related to a problem? Please describe.

Describe the solution you’d like

I originally sent https://github.com/sveltejs/sapper/pull/1336 though it might not solve all requests. E.g. there was a request to time how long load takes and I don’t think my solution would have made that easy to do, so it should probably be updated a bit to account for that.

How important is this feature to you?

This enables a large number of use cases for advanced users, so is fairly important.

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:24 (21 by maintainers)

github_iconTop GitHub Comments

1reaction
benmccanncommented, Jan 15, 2021

Loader context doesn’t seem like it solves the timing / metrics gathering use case. If you want to instrument how long your load calls take I’m not sure how you would do that using only loader context. If we want to punt on that I’m okay with that because loader context will solve the rest of the use cases. I just think that we need to be aware that we might need to add some type of additional instrumentation hooks in the future if we go with loader context now.

If we decide to go the loader context route - I didn’t like that in Rich’s example that I’d have to change every call to fetch to special_fetch throughout the codebase. I would prefer that SvelteKit’s implementation of fetch is provided in the context so that I can just override it with my own version

1reaction
Rich-Harriscommented, Jan 15, 2021

Can these cases be accommodated with loader context? i.e.

<!-- routes/$layout.svelte -->
<script context="module">
  export async function load({ fetch }) {
    return {
      context: {
        special_fetch = make_special(fetch);
      }
    };
  }
</script>
<!-- everywhere else -->
<script context="module">
  export async function load({ context }) {
    const stuff = await context.special_fetch('/stuff.json');
    // ...
  }
</script>
Read more comments on GitHub >

github_iconTop Results From Across the Web

Amazon EC2 Auto Scaling lifecycle hooks
Amazon EC2 Auto Scaling offers the ability to add lifecycle hooks to your Auto Scaling groups. These hooks let you create solutions that...
Read more >
reactjs - With useEffect, how can I skip applying an effect upon ...
As the guide states,. The Effect Hook, useEffect, adds the ability to perform side effects from a function component.
Read more >
The last guide to the useEffect Hook you'll ever need
Understanding how the useEffect Hook works, and why it requires a wholesale shift in mindset, is essential to writing modern React code.
Read more >
Lifecycle hooks - Angular
See details in Using change detection hooks in this document. Called before ngOnInit() (if the component has bound inputs) and whenever one or...
Read more >
Hooks FAQ - React
They don't fundamentally change how React works, and your knowledge of components, ... Whether a component is a class or a function that...
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