diff --git a/.changeset/start-client-setup.md b/.changeset/start-client-setup.md new file mode 100644 index 0000000..3e203da --- /dev/null +++ b/.changeset/start-client-setup.md @@ -0,0 +1,7 @@ +--- +'@solidjs/vite-plugin': patch +--- + +New `start.clientSetup` option: a client module the generated client entry runs before it hydrates or mounts the app. Use it to install a server-function transport wrapper, a `vite:preloadError` listener, or an error reporter before the first render, without writing your own `entry-client` / `entry-server` pair. The module may use top-level `await`, and `hydrate()` / `render()` waits for it. Combining it with an authored `entry-client` is a config error. + +The start options list in the README now also names `instrument`. diff --git a/README.md b/README.md index ecbe858..66f402e 100644 --- a/README.md +++ b/README.md @@ -234,7 +234,8 @@ same server functions. The object form carries the options (`start: true` is pure sugar for `start: {}` — both mean the identical start mode with defaults, and `false`/absent means off): `app`, `document`, `entryServer`, `entryClient`, -`middleware`, `setup`, `renderMode`, `env`, `devtools`, `errorBoundary`, +`middleware`, `setup`, `instrument`, `clientSetup`, `renderMode`, `env`, +`devtools`, `errorBoundary`, `css`, `external`, `node`, all documented below. Install `@solidjs/start-devtools` as a development dependency to add the @@ -565,6 +566,39 @@ instrument.mjs` dance. The module may be async and needs no exports; the server build must keep code splitting on (the default), since inlining dynamic imports would hoist the handler graph back above the instrument. +**`clientSetup`** points at a client module that the generated client entry +runs before it hydrates (SSR mode) or mounts (client mode) the app. Use it +for browser setup that must be in place before the first render: + +- a server-function transport wrapper or request-header hook, +- a `vite:preloadError` listener, +- an error reporter's `init()`. + +```ts +// vite.config.ts +solid({ start: { clientSetup: './src/client-setup.ts' }, ssr: true }); + +// src/client-setup.ts +window.addEventListener('vite:preloadError', () => window.location.reload()); +``` + +How it runs: + +- The generated entry imports the module for its side effects, ahead of the + app. A synchronous module finishes before the app's modules evaluate. +- The module may use top-level `await`. `hydrate()` / `render()` waits for + it to settle. The app's modules may evaluate while it waits, but nothing + renders. +- Because it can wait, it can read a global that a classic `