Skip to content

Commit

Permalink
docs: improve FAQ navbar (#13450)
Browse files Browse the repository at this point in the history
* docs: improve FAQ navbar

* chore: Fix build errors, probably

---------

Co-authored-by: S. Elliott Johnson <[email protected]>
  • Loading branch information
1 parent 3b2caa1 commit 1997c0d
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ For testing the build, you should use [wrangler](https://developers.cloudflare.c

### Worker size limits

When deploying to workers, the server generated by SvelteKit is bundled into a single file. Wrangler will fail to publish your worker if it exceeds [the size limits](https://developers.cloudflare.com/workers/platform/limits/#worker-size) after minification. You're unlikely to hit this limit usually, but some large libraries can cause this to happen. In that case, you can try to reduce the size of your worker by only importing such libraries on the client side. See [the FAQ](./faq#How-do-I-use-X-with-SvelteKit-How-do-I-use-a-client-side-only-library-that-depends-on-document-or-window) for more information.
When deploying to workers, the server generated by SvelteKit is bundled into a single file. Wrangler will fail to publish your worker if it exceeds [the size limits](https://developers.cloudflare.com/workers/platform/limits/#worker-size) after minification. You're unlikely to hit this limit usually, but some large libraries can cause this to happen. In that case, you can try to reduce the size of your worker by only importing such libraries on the client side. See [the FAQ](./faq#How-do-I-use-a-client-side-library-accessing-document-or-window) for more information.

### Accessing the file system

Expand Down
18 changes: 9 additions & 9 deletions documentation/docs/60-appendix/10-faq.md
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ Libraries work best in the browser with Vite when they distribute an ESM version
If you are still encountering issues we recommend searching both [the Vite issue tracker](https://github.com/vitejs/vite/issues) and the issue tracker of the library in question. Sometimes issues can be worked around by fiddling with the [`optimizeDeps`](https://vitejs.dev/config/#dep-optimization-options) or [`ssr`](https://vitejs.dev/config/#ssr-options) config values though we recommend this as only a short-term workaround in favor of fixing the library in question.
## How do I use the view transitions API with SvelteKit?
## How do I use the view transitions API?
While SvelteKit does not have any specific integration with [view transitions](https://developer.chrome.com/docs/web-platform/view-transitions/), you can call `document.startViewTransition` in [`onNavigate`]($app-navigation#onNavigate) to trigger a view transition on every client-side navigation.
Expand All @@ -81,15 +81,13 @@ onNavigate((navigation) => {
For more, see ["Unlocking view transitions"](/blog/view-transitions) on the Svelte blog.
## How do I use X with SvelteKit?
Make sure you've read the [documentation section on integrations](./integrations). If you're still having trouble, solutions to common issues are listed below.
### How do I setup a database?
## How do I set up a database?
Put the code to query your database in a [server route](./routing#server) - don't query the database in .svelte files. You can create a `db.js` or similar that sets up a connection immediately and makes the client accessible throughout the app as a singleton. You can execute any one-time setup code in `hooks.server.js` and import your database helpers into any endpoint that needs them.
### How do I use a client-side only library that depends on `document` or `window`?
You can use [the Svelte CLI](/docs/cli/overview) to automatically set up database integrations.
## How do I use a client-side library accessing `document` or `window`?
If you need access to the `document` or `window` variables or otherwise need code to run only on the client-side you can wrap it in a `browser` check:
Expand Down Expand Up @@ -157,7 +155,7 @@ Finally, you may also consider using an `{#await}` block:
{/await}
```
### How do I use a different backend API server?
## How do I use a different backend API server?
You can use [`event.fetch`](./load#Making-fetch-requests) to request data from an external API server, but be aware that you would need to deal with [CORS](https://developer.mozilla.org/en-US/docs/Web/HTTP/CORS), which will result in complications such as generally requiring requests to be preflighted resulting in higher latency. Requests to a separate subdomain may also increase latency due to an additional DNS lookup, TLS setup, etc. If you wish to use this method, you may find [`handleFetch`](./hooks#Server-hooks-handleFetch) helpful.
Expand All @@ -175,7 +173,7 @@ export function GET({ params, url }) {
(Note that you may also need to proxy `POST`/`PATCH` etc requests, and forward `request.headers`, depending on your needs.)
### How do I use middleware?
## How do I use middleware?
`adapter-node` builds a middleware that you can use with your own server for production mode. In dev, you can add middleware to Vite by using a Vite plugin. For example:
Expand Down Expand Up @@ -209,6 +207,8 @@ export default config;
See [Vite's `configureServer` docs](https://vitejs.dev/guide/api-plugin.html#configureserver) for more details including how to control ordering.
## How do I use Yarn?
### Does it work with Yarn 2?
Sort of. The Plug'n'Play feature, aka 'pnp', is broken (it deviates from the Node module resolution algorithm, and [doesn't yet work with native JavaScript modules](https://github.com/yarnpkg/berry/issues/638) which SvelteKit — along with an [increasing number of packages](https://blog.sindresorhus.com/get-ready-for-esm-aa53530b3f77) — uses). You can use `nodeLinker: 'node-modules'` in your [`.yarnrc.yml`](https://yarnpkg.com/configuration/yarnrc#nodeLinker) file to disable pnp, but it's probably easier to just use npm or [pnpm](https://pnpm.io/), which is similarly fast and efficient but without the compatibility headaches.
Expand Down
2 changes: 1 addition & 1 deletion documentation/docs/60-appendix/20-integrations.md
Original file line number Diff line number Diff line change
Expand Up @@ -49,4 +49,4 @@ Since SvelteKit projects are built with Vite, you can use Vite plugins to enhanc

## Integration FAQs

The SvelteKit FAQ has a [how to do X with SvelteKit](./faq#How-do-I-use-X-with-SvelteKit), which may be helpful if you still have questions.
The SvelteKit FAQ has a [how to do X with SvelteKit](./faq#How-do-I-set-up-a-database), which may be helpful if you still have questions.

0 comments on commit 1997c0d

Please sign in to comment.