@@ -73,6 +73,49 @@ export default function viteReactServerRuntime() {
7373 }
7474 return moduleCache.get(id);
7575 };` ;
76+ } else if ( id . endsWith ( "@__disable_hmr__" ) ) {
77+ return `(function () {
78+ if (typeof WebSocket === 'undefined') return;
79+ const Orig = WebSocket;
80+ function isViteHmr(protocols) {
81+ if (protocols === 'vite-hmr') return true;
82+ if (Array.isArray(protocols) && protocols.indexOf('vite-hmr') !== -1) return true;
83+ return false;
84+ }
85+ function InertSocket() {
86+ // Matches the surface @vite/client touches: readyState, send, close,
87+ // addEventListener, removeEventListener, onopen/onmessage/onerror/onclose.
88+ const listeners = {};
89+ this.readyState = 3; // CLOSED
90+ this.url = '';
91+ this.protocol = 'vite-hmr';
92+ this.send = function () {};
93+ this.close = function () {};
94+ this.addEventListener = function (type, fn) {
95+ (listeners[type] || (listeners[type] = [])).push(fn);
96+ };
97+ this.removeEventListener = function (type, fn) {
98+ var l = listeners[type]; if (!l) return;
99+ var i = l.indexOf(fn); if (i !== -1) l.splice(i, 1);
100+ };
101+ this.onopen = this.onmessage = this.onerror = this.onclose = null;
102+ }
103+ InertSocket.CONNECTING = 0;
104+ InertSocket.OPEN = 1;
105+ InertSocket.CLOSING = 2;
106+ InertSocket.CLOSED = 3;
107+
108+ window.WebSocket = function (url, protocols) {
109+ if (isViteHmr(protocols)) return new InertSocket();
110+ return new Orig(url, protocols);
111+ };
112+ // Preserve statics so libraries that read WebSocket.OPEN etc. keep working.
113+ window.WebSocket.CONNECTING = Orig.CONNECTING;
114+ window.WebSocket.OPEN = Orig.OPEN;
115+ window.WebSocket.CLOSING = Orig.CLOSING;
116+ window.WebSocket.CLOSED = Orig.CLOSED;
117+ window.WebSocket.prototype = Orig.prototype;
118+ })();` ;
76119 }
77120 } ,
78121 } ,
0 commit comments