@dokebi/template-inertia 0.4.17 → 0.4.18
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/AI.md +1 -0
- package/dist/index.js +43 -1
- package/dist/vite-dev.d.ts +7 -0
- package/dist/vite-dev.js +11 -0
- package/package.json +3 -3
package/AI.md
CHANGED
|
@@ -265,6 +265,7 @@ A module keeps its Vue pages in its own views folder (@dokebi/module AI.md §4a)
|
|
|
265
265
|
- The same host check as the dev routes runs first (loopback names, IPs, @dokebi/app domains, `devHosts`; others get `403`). Behind a tunnel set dokebi-web `trustProxy` so the tunnel's host is seen (@dokebi/web AI.md §2.6). A host that cannot reach Vite is logged at error `INERTIA_VITE_DEV_FAILED` once per window.
|
|
266
266
|
- Vite's token check (protection against cross-site WebSocket hijacking) stays. Upgrades that are not Vite's subprotocols are cut. Closing the host closes its port and connections, and a host whose Vite fails to start closes its port.
|
|
267
267
|
- **Late file events are no edits (D-0045 addendum 4, 0.4.3)**: on macOS, FSEvents also delivers events for writes made before the watch started (`dokebi init`, `dokebi add`, `npm install`, a checkout), minutes late when fseventsd is busy. The host records each module file's state (device, inode, size, modification time) when Vite first loads it in an environment (before Vite reads it) and the `vite.config.*` files before Vite starts, and drops a watcher `change`, `add` or `unlink` whose file state equals every recorded one, so such an event invalidates nothing, sends no reload or update (a reload was buffered for the first page that connected) and restarts nothing. Any other event goes on at once. Files Vite never loaded through its plugin pipeline are not filtered. A save that changes nothing but the modification time is still an edit.
|
|
268
|
+
- **The drain ends the open HMR sockets (0.4.18, [D-0288](https://git.nyx-zone.com/dokebi/framework/-/blob/main/docs/decisions/D-0288-dev-kills-after-the-apps-stop-deadlines.md))**: the Vite host outlives a `dokebi dev` restart, so nothing else closes a socket the app joined to it; next to @dokebi/websocket each one is a hijacked request web's drain waits for, and an open page held every restart to the drain deadline (center dev: `Web drain started pending: 2` for one tab, then the process was killed). On drain they end (debug `INERTIA_VITE_HMR_ENDED` with the count) and an HMR upgrade after that is answered 503; the page's Vite client reconnects to the next app and reloads, as it did when the process ended.
|
|
268
269
|
- **Edits the watcher missed are read anyway (D-0283, 0.4.17)**: FSEvents can report an edit a minute late, or not before the next page load (a `git pull` that restarted the app while the host kept serving the old `.vue`, and the page broke on its new locales). The same records serve a comparison: when an app process connects (`trigger` `client`), before a server render (`ssr`) and when a page loads `<base>@vite/client` (`page`), the host compares every file Vite read with its state on disk. A file that changed is invalidated in every module graph at once and handed to Vite as the watcher's `change` (`unlink` when it is gone), so plugins, HMR updates and reloads run as for the watcher's own event, and the request that follows gets the file as it is; the watcher's late event then changes nothing and is dropped. Each find is info `INERTIA_VITE_WATCH_MISSED` (`trigger`, `files`, `sample` of at most 5, `compared`, `ms`). Open pages still get their immediate HMR from the watcher; the comparison guarantees that a reloaded page or a restarted app gets the files on disk.
|
|
269
270
|
- **Pre-bundled dependencies that load (D-0128, 0.4.4)**: Vite keeps what its dependency optimizer wrote (each dependency's file under `node_modules/.vite/deps` and the `?v=` hash pages get) in memory, and at start trusts `_metadata.json` whenever the lockfile and config hashes match; it never looks at the files again, and it answers a file that is gone with 504 "Outdated Optimize Dep". A folder changed under it (two Vite optimizers on one folder — two `dokebi dev` sessions, a host still closing while the next starts — or a reinstall) therefore left every page blank through app restarts and dev restarts, until `rm -rf node_modules/.vite`. The host now compares its optimizer's files and metadata hashes with the folder when it starts, whenever an app process connects (every app or worker start) and after it answered a 504; when they differ it removes the deps folder and restarts its Vite (warn `INERTIA_VITE_DEPS_STALE` with `trigger` `start`, `client` or `outdated`, `drift` `missing` or `rewritten`, and a sample of the missing files), and the app process is answered after the repair. Open pages reconnect HMR and reload; a new page load gets the new hashes. At most one repair per `devDepsRepairIntervalMs`; faster changes are reported with warn `INERTIA_VITE_DEPS_CHANGING`. The host records its pid in `<cacheDir>/.dokebi/vite-host.json` and warns `INERTIA_VITE_HOST_SHARED` when another live host recorded itself there (stop one of the two `dokebi dev`). App processes pass Vite's status text on (`504 Outdated Optimize Dep`).
|
|
270
271
|
- SSR: the host runs `ssrLoadModule(<source entry>)` and `render(page)` per request. The app process asks on connections of its own (a render that waits never holds the connections module requests are forwarded on) and cuts the request at `ssr.timeoutMs`, so renders that never finish do not pile up on the host. The source entry is `ssr.entry` (for example `src/apps/admin/views/ssr.js`), otherwise `ssr.js` in the folder of `vite.entry`. When neither exists the start fails (`SSR_ENTRY_MISSING`).
|
package/dist/index.js
CHANGED
|
@@ -364,10 +364,45 @@ function parseEntry(input) {
|
|
|
364
364
|
class InertiaRuntime {
|
|
365
365
|
settings;
|
|
366
366
|
entry;
|
|
367
|
+
/** D-0288: the Vite dev connection once opened (development only), for the drain. */
|
|
368
|
+
#devServer;
|
|
369
|
+
/** D-0288: set when the app drains; an HMR upgrade after it is not joined (503). */
|
|
370
|
+
#dev = { draining: false };
|
|
367
371
|
constructor(settings, entry) {
|
|
368
372
|
this.settings = settings;
|
|
369
373
|
this.entry = entry;
|
|
370
374
|
}
|
|
375
|
+
/**
|
|
376
|
+
* D-0288: the HMR sockets joined to the Vite dev host end when the app drains. The host
|
|
377
|
+
* outlives a `dokebi dev` restart, so nothing else closes them: through a WebSocket plugin each
|
|
378
|
+
* is a hijacked request web's drain counted until its deadline (center dev: "Web drain started
|
|
379
|
+
* pending: 2" for one open page, then the process was killed). The page's Vite client
|
|
380
|
+
* reconnects to the next app and reloads, as it did when the process ended.
|
|
381
|
+
*/
|
|
382
|
+
async drain(context) {
|
|
383
|
+
this.#dev.draining = true;
|
|
384
|
+
const opened = this.#devServer?.();
|
|
385
|
+
if (!opened)
|
|
386
|
+
return;
|
|
387
|
+
let vite;
|
|
388
|
+
try {
|
|
389
|
+
vite = await opened;
|
|
390
|
+
}
|
|
391
|
+
catch (error) {
|
|
392
|
+
// It never opened (its failure was said where it was awaited): nothing was joined.
|
|
393
|
+
if (context.logger.isEnabled('debug'))
|
|
394
|
+
context.logger.log('debug', 'Vite HMR sockets: the dev server never opened', {
|
|
395
|
+
error: describeError(error),
|
|
396
|
+
});
|
|
397
|
+
return;
|
|
398
|
+
}
|
|
399
|
+
const sockets = vite.endUpgrades();
|
|
400
|
+
if (sockets > 0)
|
|
401
|
+
context.logger.log('debug', 'Vite HMR sockets ended for the drain', {
|
|
402
|
+
code: 'INERTIA_VITE_HMR_ENDED',
|
|
403
|
+
sockets,
|
|
404
|
+
});
|
|
405
|
+
}
|
|
371
406
|
async setup(context) {
|
|
372
407
|
const server = context.getDependency(web);
|
|
373
408
|
const logger = context.logger;
|
|
@@ -561,6 +596,8 @@ class InertiaRuntime {
|
|
|
561
596
|
const routeIds = this.settings.routeIds;
|
|
562
597
|
const repeats = new Repeats({ intervalMs: limits.logRepeatWindowMs });
|
|
563
598
|
let devServer;
|
|
599
|
+
this.#devServer = () => devServer;
|
|
600
|
+
const dev = this.#dev;
|
|
564
601
|
const devBases = new Set();
|
|
565
602
|
// Vite refuses hosts it does not know (DNS rebinding). Its check is off (one Vite serves
|
|
566
603
|
// every app); instead the dev routes check the host themselves: loopback names, IPs, the
|
|
@@ -604,6 +641,11 @@ class InertiaRuntime {
|
|
|
604
641
|
};
|
|
605
642
|
/** Joins one Vite upgrade to the host after the dev routes' host check. */
|
|
606
643
|
const joinUpgrade = (request, socket, head, base) => {
|
|
644
|
+
// D-0288: the app drains; the page's client tries again and reaches the next app.
|
|
645
|
+
if (dev.draining) {
|
|
646
|
+
socket.end('HTTP/1.1 503 Service Unavailable\r\nConnection: close\r\nContent-Length: 0\r\n\r\n');
|
|
647
|
+
return;
|
|
648
|
+
}
|
|
607
649
|
const host = hostName(request);
|
|
608
650
|
if (!devHosts.allows(host)) {
|
|
609
651
|
if (logger.isEnabled('debug'))
|
|
@@ -1065,7 +1107,7 @@ class InertiaRuntime {
|
|
|
1065
1107
|
}
|
|
1066
1108
|
export const createPlugin = definePlugin({
|
|
1067
1109
|
name: 'dokebi-template-inertia',
|
|
1068
|
-
version: '0.4.
|
|
1110
|
+
version: '0.4.18',
|
|
1069
1111
|
core: '^0.4.2',
|
|
1070
1112
|
options,
|
|
1071
1113
|
entry: parseEntry,
|
package/dist/vite-dev.d.ts
CHANGED
|
@@ -60,6 +60,13 @@ export interface ViteDev {
|
|
|
60
60
|
* the page's own origin (a tunnel, a proxy), never the host's loopback port.
|
|
61
61
|
*/
|
|
62
62
|
upgrade(request: IncomingMessage, socket: Duplex, head: Buffer, report: (error: unknown) => void): void;
|
|
63
|
+
/**
|
|
64
|
+
* D-0288: ends the HMR sockets joined so far (each with its connection to the host) and
|
|
65
|
+
* answers how many. Called when the app drains: the host outlives a `dokebi dev` restart, so
|
|
66
|
+
* nothing else ends them, and a socket a WebSocket plugin routed through Fastify is a hijacked
|
|
67
|
+
* request web's drain waits for. The page's Vite client reconnects to the next app.
|
|
68
|
+
*/
|
|
69
|
+
endUpgrades(): number;
|
|
63
70
|
/** Releases this process's connections (and its own host, when it started one). */
|
|
64
71
|
close(): Promise<void>;
|
|
65
72
|
}
|
package/dist/vite-dev.js
CHANGED
|
@@ -523,6 +523,8 @@ export async function connectViteDev(logger, url, key) {
|
|
|
523
523
|
logger.log('debug', 'Vite dev host connected', { url: target.origin, hmr: sources });
|
|
524
524
|
/** HMR sockets joined to the host, ended by close(). */
|
|
525
525
|
const joined = new Set();
|
|
526
|
+
/** The end of each joined upgrade (D-0288: the drain ends them). */
|
|
527
|
+
const ends = new Set();
|
|
526
528
|
return {
|
|
527
529
|
hmrSources: Object.freeze(sources),
|
|
528
530
|
upgrade(request, socket, head, report) {
|
|
@@ -534,11 +536,13 @@ export async function connectViteDev(logger, url, key) {
|
|
|
534
536
|
if (ended)
|
|
535
537
|
return;
|
|
536
538
|
ended = true;
|
|
539
|
+
ends.delete(end);
|
|
537
540
|
joined.delete(socket);
|
|
538
541
|
joined.delete(upstream);
|
|
539
542
|
socket.destroy();
|
|
540
543
|
upstream.destroy();
|
|
541
544
|
};
|
|
545
|
+
ends.add(end);
|
|
542
546
|
upstream.once('connect', () => {
|
|
543
547
|
// The handshake as the browser sent it (rawHeaders keeps names, order and repeats; Node
|
|
544
548
|
// refused any line break in them): Vite checks the token and the subprotocol itself.
|
|
@@ -627,6 +631,12 @@ export async function connectViteDev(logger, url, key) {
|
|
|
627
631
|
return answer.result;
|
|
628
632
|
throw remoteError(answer.error ?? { message: `Vite dev host answered ${status}` });
|
|
629
633
|
},
|
|
634
|
+
endUpgrades: () => {
|
|
635
|
+
const count = ends.size;
|
|
636
|
+
for (const end of [...ends])
|
|
637
|
+
end();
|
|
638
|
+
return count;
|
|
639
|
+
},
|
|
630
640
|
close: async () => {
|
|
631
641
|
agent.destroy();
|
|
632
642
|
renders.destroy();
|
|
@@ -667,6 +677,7 @@ export async function openViteDev(logger, environment = process.env, root = proc
|
|
|
667
677
|
forward: client.forward,
|
|
668
678
|
render: client.render,
|
|
669
679
|
upgrade: client.upgrade,
|
|
680
|
+
endUpgrades: client.endUpgrades,
|
|
670
681
|
close: async () => {
|
|
671
682
|
try {
|
|
672
683
|
await client.close();
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@dokebi/template-inertia",
|
|
3
|
-
"version": "0.4.
|
|
3
|
+
"version": "0.4.18",
|
|
4
4
|
"description": "Inertia v3 server adapter for Dokebi: page JSON, Vite manifest assets and optional server-side rendering.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"dokebi",
|
|
@@ -144,8 +144,8 @@
|
|
|
144
144
|
},
|
|
145
145
|
"devDependencies": {
|
|
146
146
|
"@dokebi/i18n": "0.2.9",
|
|
147
|
-
"@dokebi/session": "0.4.
|
|
148
|
-
"@dokebi/web": "0.4.
|
|
147
|
+
"@dokebi/session": "0.4.11",
|
|
148
|
+
"@dokebi/web": "0.4.26",
|
|
149
149
|
"@dokebi/websocket": "0.4.10",
|
|
150
150
|
"@dokebi/websocket-hub": "0.4.5",
|
|
151
151
|
"@inertiajs/vue3": "3.9.1",
|