Skip to content

Commit c6f3a8d

Browse files
authored
[Custom client.js] Partial load on default paths (#447)
* [Custom client.js] Partial load on default paths * more readme * format * better readme * correct path
1 parent c4e348e commit c6f3a8d

File tree

4 files changed

+2157
-2
lines changed

4 files changed

+2157
-2
lines changed

kit/package.json

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,9 @@
33
"version": "0.0.1",
44
"private": true,
55
"scripts": {
6-
"dev": "vite dev",
7-
"build": "rm -Rf src/routes/__pycache__ && vite build && node postprocess && ./postbuild.sh",
6+
"custom-svelte-client": "node ./svelteKitCustomClient/replace",
7+
"dev": "npm run custom-svelte-client && vite dev",
8+
"build": "npm run custom-svelte-client && rm -Rf src/routes/__pycache__ && vite build && node postprocess && ./postbuild.sh",
89
"preview": "vite preview",
910
"check": "svelte-kit sync && svelte-check --tsconfig ./tsconfig.json",
1011
"check:watch": "svelte-kit sync && svelte-check --tsconfig ./tsconfig.json --watch",
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
# Custom `sveltekit client.js` file
2+
3+
Sveltekit handles [internal routes](https://kit.svelte.dev/docs/routing) by:
4+
5+
1. partially loading changed components
6+
2. updating the browser's [history](https://developer.mozilla.org/en-US/docs/Web/API/History)
7+
8+
which makes the user experience better by not loading/reloading pages completely from scratch.
9+
10+
### Hugging Face docs
11+
12+
In [hf docs](https://huggingface.co/docs), we have these redirection rules:
13+
14+
```
15+
hf.co/docs/lib/page -> hf.co/docs/lib/default_version/default_lang/page
16+
hf.co/docs/lib/version/page -> hf.co/docs/lib/version/default_lang/page
17+
```
18+
19+
However, these rules were being handled as external routes by SvelteKit without taking advantage of partial reloadings. I've tried using [$app/navigation](https://kit.svelte.dev/docs/modules#$app-navigation) without success. Therefore, the simplest solution was: overwriting [sveltekit client.js](https://github.com/sveltejs/kit/blob/master/packages/kit/src/runtime/client/client.js) to handle hf doc routes accordingly.
20+
21+
Specifically, this [custom client.js](https://github.com/huggingface/doc-builder/blob/ab03d33801595579591ac8cdc49514c4f59fe068/kit/svelteKitCustomClient/client.js) is identical to [sveltekit client.js](https://github.com/sveltejs/kit/blob/master/packages/kit/src/runtime/client/client.js) with only one difference: addition and usage of [getHfDocFullPath function](https://github.com/huggingface/doc-builder/blob/ab03d33801595579591ac8cdc49514c4f59fe068/kit/svelteKitCustomClient/client.js#L43), which makes it possible for hf redirected paths (as described above) to be considered as `internal routes` and take full advantage of partial loading.

0 commit comments

Comments
 (0)