@ripple-ts/vite-plugin 0.2.214 → 0.2.216

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/CHANGELOG.md CHANGED
@@ -1,5 +1,19 @@
1
1
  # @ripple-ts/vite-plugin
2
2
 
3
+ ## 0.2.216
4
+
5
+ ### Patch Changes
6
+
7
+ - Updated dependencies []:
8
+ - @ripple-ts/adapter@0.2.216
9
+
10
+ ## 0.2.215
11
+
12
+ ### Patch Changes
13
+
14
+ - Updated dependencies []:
15
+ - @ripple-ts/adapter@0.2.215
16
+
3
17
  ## 0.2.214
4
18
 
5
19
  ### Patch Changes
package/package.json CHANGED
@@ -3,7 +3,7 @@
3
3
  "description": "Vite plugin for Ripple",
4
4
  "license": "MIT",
5
5
  "author": "Dominic Gannaway",
6
- "version": "0.2.214",
6
+ "version": "0.2.216",
7
7
  "type": "module",
8
8
  "module": "src/index.js",
9
9
  "main": "src/index.js",
@@ -32,12 +32,12 @@
32
32
  "url": "https://github.com/Ripple-TS/ripple/issues"
33
33
  },
34
34
  "dependencies": {
35
- "@ripple-ts/adapter": "0.2.214"
35
+ "@ripple-ts/adapter": "0.2.216"
36
36
  },
37
37
  "devDependencies": {
38
38
  "type-fest": "^5.1.0",
39
39
  "vite": "^7.1.9",
40
- "ripple": "0.2.214"
40
+ "ripple": "0.2.216"
41
41
  },
42
42
  "publishConfig": {
43
43
  "access": "public"
package/src/index.js CHANGED
@@ -607,6 +607,51 @@ export function ripple(inlineOptions = {}) {
607
607
  };
608
608
  },
609
609
 
610
+ /**
611
+ * Handle HMR for files that Vite's default module HMR can't
612
+ * properly refresh.
613
+ *
614
+ * .ripple components self-accept HMR and swap their component
615
+ * function. For changes to their OWN code this works perfectly.
616
+ * But for changes to DEPENDENCIES (e.g. .md files imported via
617
+ * import.meta.glob), the self-accept handler can't refresh
618
+ * static imports cached in the browser's ESM module registry.
619
+ *
620
+ * Strategy:
621
+ * - If all changed modules self-accept → they can hot-replace
622
+ * themselves (e.g. .ripple components, CSS). Let Vite handle.
623
+ * - Otherwise, check the SSR module graph. If the file is there,
624
+ * invalidate SSR cache and trigger a full page reload.
625
+ */
626
+ hotUpdate({ file, modules, server }) {
627
+ if (this.environment.name !== 'client') return;
628
+
629
+ // If all changed modules self-accept, they can hot-replace
630
+ // themselves (.ripple components, CSS modules). Let Vite
631
+ // handle without intervention.
632
+ if (modules.length > 0 && modules.every((m) => m.isSelfAccepting)) {
633
+ return;
634
+ }
635
+
636
+ // Check if this file is part of the SSR module graph.
637
+ const ssr = server.environments.ssr;
638
+ if (!ssr) return;
639
+
640
+ const ssr_modules = ssr.moduleGraph.getModulesByFile(file);
641
+ if (!ssr_modules || ssr_modules.size === 0) return;
642
+
643
+ // Invalidate SSR modules so the server re-reads the file
644
+ // on next request instead of serving stale cached content.
645
+ for (const mod of ssr_modules) {
646
+ ssr.moduleGraph.invalidateModule(mod);
647
+ }
648
+
649
+ // Full reload — the only reliable way to pick up the change
650
+ // for files that don't self-accept but are consumed by the app.
651
+ this.environment.hot.send({ type: 'full-reload' });
652
+ return [];
653
+ },
654
+
610
655
  /**
611
656
  * Inject the hydration script into the HTML template during build.
612
657
  * In dev mode, this is handled by render-route.js instead.
@@ -978,9 +1023,12 @@ import { hydrate, mount } from 'ripple';
978
1023
  const filename = id.replace(root, '');
979
1024
  const ssr = opts?.ssr === true || this.environment.config.consumer === 'server';
980
1025
 
1026
+ const is_dev = config?.command === 'serve';
1027
+
981
1028
  const { js, css } = await compile(code, filename, {
982
1029
  mode: ssr ? 'server' : 'client',
983
- dev: config?.command === 'serve',
1030
+ dev: is_dev,
1031
+ hmr: is_dev && !ssr,
984
1032
  });
985
1033
 
986
1034
  // Track modules with #server blocks for RPC (client build only)
@@ -50,7 +50,7 @@ export function createHandler(manifest, options) {
50
50
  const { render, getCss, htmlTemplate, executeServerFunction } = options;
51
51
  const router = createRouter(manifest.routes);
52
52
  const globalMiddlewares = manifest.middlewares;
53
- const trustProxy = manifest.trustProxy;
53
+ const trustProxy = manifest.trustProxy ?? false;
54
54
  const clientAssets = manifest.clientAssets || {};
55
55
 
56
56
  // Use adapter's runtime primitives for platform-agnostic operation
@@ -63,9 +63,9 @@ export function createHandler(manifest, options) {
63
63
 
64
64
  // Create async context and patch fetch for relative URL resolution in #server blocks
65
65
  const asyncContext = runtime.createAsyncContext();
66
- patch_global_fetch(asyncContext);
66
+ const fetchHandle = patch_global_fetch(asyncContext);
67
67
 
68
- return async function handler(request) {
68
+ const handler = async function handler(/** @type {Request} */ request) {
69
69
  const url = new URL(request.url);
70
70
  const method = request.method;
71
71
 
@@ -114,6 +114,13 @@ export function createHandler(manifest, options) {
114
114
  return new Response('Internal Server Error', { status: 500 });
115
115
  }
116
116
  };
117
+
118
+ // Enable same-origin fetch short-circuit: server-side fetch() calls that
119
+ // resolve to the same origin are routed directly through this handler
120
+ // in-process, instead of making a real network request.
121
+ fetchHandle.set_handler(handler);
122
+
123
+ return handler;
117
124
  }
118
125
 
119
126
  // ============================================================================
package/tsconfig.json ADDED
@@ -0,0 +1,8 @@
1
+ {
2
+ "compilerOptions": {
3
+ "allowJs": true,
4
+ "noEmit": true
5
+ },
6
+ "include": ["./src/**/*", "./tests/**/*"],
7
+ "exclude": ["dist", "node_modules"]
8
+ }