Skip to content

Commit 6e967ff

Browse files
docs: update FAQ entry on using client-only libraries (#10886)
Co-authored-by: Ben McCann <[email protected]>
1 parent 1968e15 commit 6e967ff

File tree

1 file changed

+20
-17
lines changed

1 file changed

+20
-17
lines changed

documentation/docs/60-appendix/01-faq.md

Lines changed: 20 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -141,21 +141,24 @@ onMount(() => {
141141
});
142142
```
143143
144-
Otherwise, if the library has side effects and you'd still prefer to use static imports, check out [vite-plugin-iso-import](https://github.com/bluwy/vite-plugin-iso-import) to support the `?client` import suffix. The import will be stripped out in SSR builds. However, note that you will lose the ability to use VS Code Intellisense if you use this method.
145-
146-
```js
147-
// @filename: ambient.d.ts
148-
// @lib: ES2015
149-
declare module 'some-browser-only-library?client';
150-
151-
// @filename: index.js
152-
// ---cut---
153-
import { onMount } from 'svelte';
154-
import { method } from 'some-browser-only-library?client';
155-
156-
onMount(() => {
157-
method('hello world');
158-
});
144+
Finally, you may also consider using an `{#await}` block:
145+
```svelte
146+
<!--- file: index.svelte --->
147+
<script>
148+
import { browser } from '$app/environment';
149+
150+
const ComponentConstructor = browser ?
151+
import('some-browser-only-library').then((module) => module.Component) :
152+
new Promise(() => {});
153+
</script>
154+
155+
{#await ComponentConstructor}
156+
<p>Loading...</p>
157+
{:then component}
158+
<svelte:component this={component} />
159+
{:catch error}
160+
<p>Something went wrong: {error.message}</p>
161+
{/await}
159162
```
160163
161164
### How do I use a different backend API server?
@@ -234,11 +237,11 @@ yarn set version berry
234237
yarn install
235238
```
236239
237-
**Yarn 3 global cache**
240+
#### Yarn 3 global cache
238241
239242
One of the more interesting features of Yarn Berry is the ability to have a single global cache for packages, instead of having multiple copies for each project on the disk. However, setting `enableGlobalCache` to true causes building to fail, so it is recommended to add the following to the `.yarnrc.yml` file:
240243
241-
```
244+
```yaml
242245
nodeLinker: node-modules
243246
```
244247

0 commit comments

Comments
 (0)