Skip to content

Commit

Permalink
chore(docs): update
Browse files Browse the repository at this point in the history
  • Loading branch information
razshare authored Apr 7, 2024
1 parent 9a702ac commit 355a12f
Showing 1 changed file with 20 additions and 22 deletions.
42 changes: 20 additions & 22 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -134,26 +134,7 @@ npm i -D sveltekit-server-session

# Don't Preload

SvelteKit comes with preload features baked in, however these feature may result in some inconsistent behavior when dealing with server state, like sessions.

Navigate to your `src/app.html` file and disable preloading by settings `data-sveltekit-preload-data` to `false` on your `body` element.

```html
<!DOCTYPE html/>
<html lang="en">
<head>
<meta charset="utf-8" />
<link rel="icon" href="%sveltekit.assets%/favicon.png" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
%sveltekit.head%
</head>
<body data-sveltekit-preload-data="false"> <!-- Here. -->
<div>%sveltekit.body%</div>
</body>
</html>
```

The reason for this is due to inconsistencies to how state may become out of sync after preloading.
SvelteKit comes with preload features baked in, however this feature may cause some inconsistent behavior when dealing with sessions.

Consider the following use case,

Expand All @@ -173,11 +154,28 @@ Consider the following use case,

Which is obviously wrong.

To fix this you need to disable preloading.

Navigate to your `src/app.html` file and disable preloading by settings `data-sveltekit-preload-data` to `false` on your `body` element.

```html
<!DOCTYPE html/>
<html lang="en">
<head>
<meta charset="utf-8" />
<link rel="icon" href="%sveltekit.assets%/favicon.png" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
%sveltekit.head%
</head>
<body data-sveltekit-preload-data="false"> <!-- Here. -->
<div>%sveltekit.body%</div>
</body>
</html>
```

You could technically disable preloading for specific cases and avoid the issue in that way, but at some point your whole application will be filled with links that point to some page that depends on the server session.\
It's just simply not worth the headache.

It's much easier and more straightforward to simply disable preloading.

> [!NOTE]
> Obviously you can still enable preload for resources like assets by manually adding
> the `data-sveltekit-preload-data="hover"` attribute to specific elements in your page.
Expand Down

0 comments on commit 355a12f

Please sign in to comment.