Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions docs/CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@ Open `http://localhost:5173` in Chrome or Edge. Firefox and Safari work too, the
- `src/lib/git` wraps isomorphic-git. `handle-fs.ts` is the file system adapter that lets it run on the project folder, `engine.ts` the operations, `errors.ts` turns its errors into something readable. The panel lives in `src/lib/ui/git`, one file per tab.
- `src/lib/project` holds the open files, the project tree and everything the toolbar calls.
- `src/lib/ui` are the Svelte components, `src/routes/editor` is the editor page itself.
- `static/sw.js` is the service worker that resolves TeX Live files on demand: cache first, then the bundled subset, then the jsDelivr mirror, then the fallback server.
- `static/texlive/cache` is the bundled package subset. If you change anything in there, bump `BUNDLE_VERSION` in `static/sw.js` and `WARMED_VERSION` in `src/lib/compiler/offline-cache.ts`, otherwise users keep the old files in their cache.
- `src/service-worker.ts` is the service worker. It keeps every file of the current build in a cache of its own, so a page that was open before a deploy still gets its chunks, and it resolves TeX Live files on demand: cache first, then the bundled subset, then the jsDelivr mirror, then the fallback server.
- `static/texlive/cache` is the bundled package subset. If you change anything in there, bump `BUNDLE_VERSION` in `src/service-worker.ts` and `WARMED_VERSION` in `src/lib/compiler/offline-cache.ts`, otherwise users keep the old files in their cache.
- `static/swiftlatex` is the engine. It is a build artifact, not something to edit by hand.

## What helps most
Expand Down
2 changes: 1 addition & 1 deletion src/lib/compiler/offline-cache.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import { base } from '$app/paths';
// down (the cache writes compete with compile i/o otherwise).

const FLAG = 'texbrain-texlive-warmed';
// matches BUNDLE_VERSION in sw.js: when the bundle changes, the warm set
// matches BUNDLE_VERSION in service-worker.ts: when the bundle changes, the warm set
// is evicted and needs one fresh run
const WARMED_VERSION = '4';
const CONCURRENCY = 2;
Expand Down
13 changes: 12 additions & 1 deletion src/routes/+layout.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,25 @@
import Toast from '$lib/ui/Toast.svelte';
import { onMount } from 'svelte';
import { browser } from '$app/environment';
import { beforeNavigate } from '$app/navigation';
import { updated } from '$app/state';
import { preferences } from '$lib/stores/preferences';
import type { Snippet } from 'svelte';

let { children }: { children: Snippet } = $props();

// after a deploy the chunks this tab knows about are gone from the server.
// a full page load on the next navigation picks up the new build instead
// of failing on a missing file
beforeNavigate(({ willUnload, to }) => {
if (updated.current && !willUnload && to?.url) {
location.href = to.url.href;
}
});

onMount(() => {
if (browser && 'serviceWorker' in navigator) {
navigator.serviceWorker.register('/sw.js').catch(() => {});
navigator.serviceWorker.register('/service-worker.js').catch(() => {});

// keep the service worker's texlive mirror config in sync
const unsubscribe = preferences.subscribe((prefs) => {
Expand Down
Loading
Loading