poveste 0.18.2 → 0.18.3

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.
@@ -7,11 +7,23 @@
7
7
  * neither the flag nor the mistake. A non-numeric value fails the same way.
8
8
  */
9
9
  export declare function resolvePort(value: unknown, command: string): number | undefined;
10
+ type SocketOptions = Record<string, unknown>;
10
11
  /**
11
- * The HMR socket port for a book served on `devPort`. Derived from the dev port
12
- * so each concurrent dev server's socket is as distinct as its book port (#175),
13
- * offset clear of the usual dev-port range and wrapped so it stays a valid port
14
- * for an unusually high `--port`. `@nuxt/vite-builder` otherwise pins every
15
- * server to the framework default (24678), a constant that collides (#221).
12
+ * The book server's HMR socket settings: whatever the merged config asked for,
13
+ * minus a port or server of its own, so Vite serves the socket on the book's port
14
+ * and the browser dials the page's own origin. Vite takes these from `server.ws`
15
+ * and from the deprecated `server.hmr` alike, so both are cleared.
16
+ *
17
+ * A socket on a second port was never routed on StackBlitz, which previews each
18
+ * port on its own hostname, so a page opened before collection ended waited for
19
+ * the list on a socket that never connected, and stayed blank (#1245). It is
20
+ * also how `@nuxt/vite-builder`'s 24678 default made two books collide (#221).
16
21
  */
17
- export declare function hmrPortFor(devPort: number | undefined): number;
22
+ export declare function socketOnBookPort(server: {
23
+ hmr?: unknown;
24
+ ws?: unknown;
25
+ }): {
26
+ hmr: SocketOptions;
27
+ ws: SocketOptions;
28
+ };
29
+ export {};
@@ -22,14 +22,24 @@ export function resolvePort(value, command) {
22
22
  }
23
23
  return port;
24
24
  }
25
+ function withoutOwnPort(options) {
26
+ if (options === null || typeof options !== 'object') {
27
+ return {};
28
+ }
29
+ const { port: _port, server: _server, ...rest } = options;
30
+ return rest;
31
+ }
25
32
  /**
26
- * The HMR socket port for a book served on `devPort`. Derived from the dev port
27
- * so each concurrent dev server's socket is as distinct as its book port (#175),
28
- * offset clear of the usual dev-port range and wrapped so it stays a valid port
29
- * for an unusually high `--port`. `@nuxt/vite-builder` otherwise pins every
30
- * server to the framework default (24678), a constant that collides (#221).
33
+ * The book server's HMR socket settings: whatever the merged config asked for,
34
+ * minus a port or server of its own, so Vite serves the socket on the book's port
35
+ * and the browser dials the page's own origin. Vite takes these from `server.ws`
36
+ * and from the deprecated `server.hmr` alike, so both are cleared.
37
+ *
38
+ * A socket on a second port was never routed on StackBlitz, which previews each
39
+ * port on its own hostname, so a page opened before collection ended waited for
40
+ * the list on a socket that never connected, and stayed blank (#1245). It is
41
+ * also how `@nuxt/vite-builder`'s 24678 default made two books collide (#221).
31
42
  */
32
- export function hmrPortFor(devPort) {
33
- const base = devPort ?? 6006;
34
- return base < 45536 ? base + 20000 : base - 20000;
43
+ export function socketOnBookPort(server) {
44
+ return { hmr: withoutOwnPort(server.hmr), ws: withoutOwnPort(server.ws) };
35
45
  }
@@ -2,7 +2,7 @@ import { performance } from 'node:perf_hooks';
2
2
  import pc from 'picocolors';
3
3
  import { createServer as createViteServer, mergeConfig as mergeViteConfig } from 'vite';
4
4
  import { useCollectStories } from './collect/index.js';
5
- import { hmrPortFor } from './commands/port.js';
5
+ import { socketOnBookPort } from './commands/port.js';
6
6
  import { useModuleLoader } from './load.js';
7
7
  import { createMarkdownFilesWatcher, onMarkdownFileChange, onMarkdownListChange } from './markdown.js';
8
8
  import { DevEventPluginApi, DevPluginApi } from './plugin.js';
@@ -42,14 +42,19 @@ async function startServer(ctx, options, onOpen, close) {
42
42
  serverConfig.hmr = false;
43
43
  }
44
44
  else {
45
- // `@nuxt/vite-builder` pins the HMR socket to the constant 24678 on every
46
- // server it configures, so two poveste dev servers on different `--port`s
47
- // collide on it and the second silently loses HMR (#221). It only does
48
- // this when `server.hmr` carries no port of its own (it fills the gap with
49
- // `defu`), so pin the socket to a port derived from this book's `--port`,
50
- // before the config is resolved: each dev server then owns a distinct one
51
- // (#175).
52
- serverConfig.hmr = { port: hmrPortFor(options.port ?? serverConfig.port) };
45
+ // On the book's own port, never a second one: StackBlitz does not route
46
+ // it, and `@nuxt/vite-builder`'s default collides between books (#1245,
47
+ // #221). Post-ordered, because that default is filled in by Nuxt's own
48
+ // `config` hook.
49
+ viteConfig.plugins = [...viteConfig.plugins ?? [], {
50
+ name: 'poveste:socket-on-book-port',
51
+ config: {
52
+ order: 'post',
53
+ handler(config) {
54
+ config.server = { ...config.server, ...socketOnBookPort(config.server ?? {}) };
55
+ },
56
+ },
57
+ }];
53
58
  if (options.open) {
54
59
  serverConfig.open = true;
55
60
  }
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "poveste",
3
3
  "type": "module",
4
- "version": "0.18.2",
4
+ "version": "0.18.3",
5
5
  "description": "Interactive component playgrounds for Vue, Nuxt, Svelte, SvelteKit and Quasar, plus Solid (renderer only) — a drop-in fork of histoire, with Quasar support histoire does not ship.",
6
6
  "author": {
7
7
  "name": "Sorin Gitlan",
@@ -77,10 +77,10 @@
77
77
  },
78
78
  "dependencies": {
79
79
  "@11ty/gray-matter": "^3.0.0",
80
- "@poveste/app": "^0.18.2",
81
- "@poveste/controls": "^0.18.2",
82
- "@poveste/shared": "^0.18.2",
83
- "@poveste/vendors": "^0.18.2",
80
+ "@poveste/app": "^0.18.3",
81
+ "@poveste/controls": "^0.18.3",
82
+ "@poveste/shared": "^0.18.3",
83
+ "@poveste/vendors": "^0.18.3",
84
84
  "change-case": "^5.4.4",
85
85
  "chokidar": "^5.0.0",
86
86
  "defu": "^6.1.4",