Usage With Svelte Kit
See original GitHub issue<script>
import Header from '$lib/layout/Header.svelte'
import Footer from '$lib/layout/Footer.svelte'
import '$lib/style/styles.scss'
import { setClient } from "svelte-apollo";
import { ApolloClient, HttpLink } from '@apollo/client/core/core.cjs.js'
import { InMemoryCache } from '@apollo/client/cache/cache.cjs.js'
const link = new HttpLink({
uri: 'http://localhost:3001/graphql',
fetch
})
const client = new ApolloClient({
link,
cache: new InMemoryCache()
})
console.log('client', client);
setClient(client);
</script>
<Header />
<slot />
<Footer />
In our __layout.svelte Produces [HMR][Svelte] Unrecoverable error in <__layout>: next update will trigger a full reload logError @ proxy.js:15 Proxy<__layout> @ proxy.js:372 create_fragment @ root.svelte? [sm]:36 init @ index.mjs?v=e94d9004:1500 Root @ root.svelte? [sm]:16 createProxiedComponent @ svelte-hooks.js:245 ProxyComponent @ proxy.js:241 Proxy<Root> @ proxy.js:341 _init @ start.js:646 start @ start.js:530 async function (async) start @ start.js:483 start @ start.js:1096 (anonymous) @ (index):39
Removing setClient(client) fixes error, breaks apollo (obviously). Any thoughts?
Uncaught (in promise) Error: Function called outside component initialization
at get_current_component (index.mjs:649)
at setContext (index.mjs:679)
at setClient (context.ts:19)
at instance (__layout.svelte? [sm]:19)
at init (index.mjs?v=e94d9004:1485)
at new _layout (__layout.svelte? [sm]:19)
at createProxiedComponent (svelte-hooks.js:245)
at new ProxyComponent (proxy.js:241)
at new Proxy<__layout> (proxy.js:341)
at create_fragment (root.svelte? [sm]:36)
Issue Analytics
- State:
- Created 2 years ago
- Reactions:7
- Comments:21
Top Results From Across the Web
Introduction • Docs • SvelteKit
SvelteKit is a framework for rapid development of robust, performant web applications. Building an app with all the modern best practices is fiendishly ......
Read more >[Tutorial] Build a website with SvelteKit - Prismic
SvelteKit uses file-system based routing. Each page is defined by a +page.svelte file, and the route for the page is the file's directory....
Read more >Getting Started with SvelteKit: 10 Tips | Rodney Lab
So to learn Svelte you could start with a basic component on your Astro app written in plain HTML and JavaScript or React...
Read more >A Beginner's Guide to SvelteKit - SitePoint
SvelteKit is an officially supported framework, built around Svelte. It adds key features to a Svelte app — such as routing, layouts and ......
Read more >Getting Started Building a Svelte App with SvelteKit
Svelte is a lightweight framework for building web applications. When you use it, it looks and feels a lot like other frontend frameworks ......
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
it looks like the library was updated 10 days ago (and there is a new release), it now includes an example with sveltekit. however just testing, I get the following error.
in case anyone else has seen and experienced this.
@vladimirdrayling Try adding
@apollo/client
tooptimizeDeps.exclude
and avoid importing@apollo/client
. Import from@apollo/client/core
instead.