GeezerVison is showing github.com — :zap: :construction: unstable hot server · nullstack/nullstack@9f6abc4
File treeExpand file treeCollapse file tree Open diff view settings Expand file treeCollapse file tree Open diff view settings Collapse file Copy file name to clipboardExpand all lines: client/index.js +20-27Lines changed: 20 additions & 27 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -2,6 +2,7 @@ import element from '../shared/element' | 2 | 2 | import fragment from '../shared/fragment' | 3 | 3 | import generateTree from '../shared/generateTree' | 4 | 4 | import { loadPlugins, useClientPlugins } from '../shared/plugins' | | 5 | +import dangerouslySilenceHmr from '../shared/silenceHmr' | 5 | 6 | import client from './client' | 6 | 7 | import context, { generateContext } from './context' | 7 | 8 | import environment from './environment' | @@ -106,46 +107,38 @@ export default class Nullstack { | 106 | 107 | } | 107 | 108 |
| 108 | 109 | if (module.hot) { | 109 | | - Nullstack.serverHashes ??= {} | 110 | | - Nullstack.serverPings = 0 | 111 | | - Nullstack.clientPings = 0 | 112 | | - const socket = new WebSocket(`ws${router.base.slice(4)}/ws`) | 113 | | - socket.onmessage = async function (e) { | 114 | | - const data = JSON.parse(e.data) | 115 | | - if (data.type === 'NULLSTACK_SERVER_STARTED') { | 116 | | - Nullstack.serverPings++ | 117 | | - if (Nullstack.needsReload || !environment.hot) { | | 110 | + dangerouslySilenceHmr() | | 111 | + | | 112 | + const source = new window.EventSource('/nullstack/hmr') | | 113 | + const pingAndReload = async () => { | | 114 | + let serverBackOnline = false | | 115 | + try { | | 116 | + const response = await fetch('/nullstack/hmr') | | 117 | + serverBackOnline = response.ok | | 118 | + } catch (e) { | | 119 | + // setTimeout(pingAndReload, 100) | | 120 | + } finally { | | 121 | + if (serverBackOnline) { | 118 | 122 | window.location.reload() | | 123 | + } else { | | 124 | + setTimeout(pingAndReload, 500) | 119 | 125 | } | 120 | 126 | } | 121 | 127 | } | | 128 | + source.onerror = pingAndReload | | 129 | + | 122 | 130 | Nullstack.updateInstancesPrototypes = function updateInstancesPrototypes(klass, hash, serverHash) { | 123 | 131 | for (const key in context.instances) { | 124 | 132 | const instance = context.instances[key] | 125 | 133 | if (instance.constructor.hash === hash) { | 126 | 134 | Object.setPrototypeOf(instance, klass.prototype) | 127 | 135 | } | 128 | 136 | } | 129 | | - if (Nullstack.serverHashes[hash]) { | 130 | | - if (Nullstack.serverHashes[hash] !== serverHash) { | 131 | | - if (Nullstack.clientPings < Nullstack.serverPings) { | 132 | | - window.location.reload() | 133 | | - } else { | 134 | | - Nullstack.needsReload = true | 135 | | - } | 136 | | - } | 137 | | - Nullstack.clientPings++ | 138 | | - } | 139 | | - Nullstack.serverHashes[hash] = serverHash | | 137 | + windowEvent('environment') | 140 | 138 | client.update() | 141 | 139 | } | 142 | | - Nullstack.hotReload = function hotReload(klass) { | 143 | | - if (client.skipHotReplacement) { | 144 | | - window.location.reload() | 145 | | - } else { | 146 | | - Nullstack.start(klass) | 147 | | - windowEvent('environment') | 148 | | - } | | 140 | + Nullstack.hotReload = function hotReload() { | | 141 | + window.location.reload() | 149 | 142 | } | 150 | 143 | module.hot.decline() | 151 | 144 | } |
Collapse file Copy file name to clipboardExpand all lines: client/instanceProxyHandler.js +5-1Lines changed: 5 additions & 1 deletion | Original file line number | Diff line number | Diff line change |
|---|
@@ -20,7 +20,11 @@ const instanceProxyHandler = { | 20 | 20 | try { | 21 | 21 | result = target[name].call(proxy, scopedContext) | 22 | 22 | } catch (error) { | 23 | | - context.catch && context.catch(error) | | 23 | + if (context.catch) { | | 24 | + context.catch(error) | | 25 | + } else { | | 26 | + throw error | | 27 | + } | 24 | 28 | return null | 25 | 29 | } | 26 | 30 | if (result instanceof Promise) { | |
Collapse file Copy file name to clipboardExpand all lines: client/worker.js +3Lines changed: 3 additions & 0 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -38,6 +38,9 @@ async function register() { | 38 | 38 | const request = `/service-worker.js` | 39 | 39 | try { | 40 | 40 | proxy.registration = await navigator.serviceWorker.register(request, { scope: '/' }) | | 41 | + if (environment.development) { | | 42 | + proxy.registration.unregister() | | 43 | + } | 41 | 44 | } catch (error) { | 42 | 45 | console.error(error) | 43 | 46 | } | |
Collapse file Copy file name to clipboardExpand all lines: loaders/add-source-to-node.js -1Lines changed: 0 additions & 1 deletion | Original file line number | Diff line number | Diff line change |
|---|
@@ -2,7 +2,6 @@ const parse = require('@babel/parser').parse | 2 | 2 | const traverse = require('@babel/traverse').default | 3 | 3 |
| 4 | 4 | module.exports = function (source) { | 5 | | - this.cacheable && this.cacheable() | 6 | 5 | const uniquePositions = new Set() | 7 | 6 | const ast = parse(source, { | 8 | 7 | sourceType: 'module', | |
Collapse file Copy file name to clipboardExpand all lines: loaders/ignore-import.js -1Lines changed: 0 additions & 1 deletion | Original file line number | Diff line number | Diff line change |
|---|
@@ -5,6 +5,5 @@ MIT Licensed | 5 | 5 | https://npmjs.com/package/ignore-loader | 6 | 6 | */ | 7 | 7 | module.exports = function () { | 8 | | - this.cacheable && this.cacheable() | 9 | 8 | return '' | 10 | 9 | } |
Collapse file Copy file name to clipboardExpand all lines: loaders/inject-hmr.js -39Lines changed: 0 additions & 39 deletions Collapse file Copy file name to clipboardExpand all lines: loaders/register-static-from-server.js +11Lines changed: 11 additions & 0 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -37,5 +37,16 @@ module.exports = function (source) { | 37 | 37 | output += `\nNullstack.registry["${legacyHash}"] = ${klassName};` | 38 | 38 | output += `\n${klassName}.hash = "${hash}";` | 39 | 39 | output += `\n${klassName}.bindStaticFunctions(${klassName});` | | 40 | + output += 'if (module.hot) {' | | 41 | + for (const methodName of methodNames) { | | 42 | + output += `\n${klassName}.${methodName}.hash = "${hash}.${methodName}";` | | 43 | + output += `\nNullstack.registry["${hash}.${methodName}"] = ${klassName}.${methodName};` | | 44 | + output += `\nNullstack.registry["${legacyHash}.${methodName}"] = ${klassName}.${methodName};` | | 45 | + } | | 46 | + output += `\nNullstack.registry["${hash}"] = ${klassName};` | | 47 | + output += `\nNullstack.registry["${legacyHash}"] = ${klassName};` | | 48 | + output += `\n${klassName}.hash = "${hash}";` | | 49 | + output += `\n${klassName}.bindStaticFunctions(${klassName});` | | 50 | + output += '}' | 40 | 51 | return output | 41 | 52 | } |
Collapse file Copy file name to clipboardExpand all lines: loaders/string-replace.js -2Lines changed: 0 additions & 2 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -4,8 +4,6 @@ MIT Licensed | 4 | 4 | Original: https://npmjs.com/package/string-replace-loader | 5 | 5 | */ | 6 | 6 | module.exports = function (source, map) { | 7 | | - this.cacheable() | 8 | | - | 9 | 7 | const optionsArray = this.getOptions().multiple | 10 | 8 | let newSource = source | 11 | 9 |
| |
Collapse file Copy file name to clipboardExpand all lines: package.json +21-19Lines changed: 21 additions & 19 deletions | Original file line number | Diff line number | Diff line change |
|---|
| 16 | 16 | }, | 17 | 17 | "dependencies": { | 18 | 18 | "@babel/core": "^7.18.13", | 19 | | - "@babel/parser": "7.17.12", | | 19 | + "@babel/parser": "7.20.15", | 20 | 20 | "@babel/plugin-proposal-class-properties": "^7.18.6", | 21 | 21 | "@babel/plugin-proposal-export-default-from": "^7.18.10", | 22 | 22 | "@babel/plugin-transform-react-jsx": "^7.18.10", | 23 | 23 | "@babel/plugin-transform-typescript": "^7.18.12", | 24 | 24 | "@babel/preset-env": "^7.18.10", | 25 | 25 | "@babel/preset-react": "^7.18.6", | 26 | | - "@babel/traverse": "7.17.12", | 27 | | - "@swc/core": "1.2.179", | 28 | | - "babel-loader": "^8.2.5", | 29 | | - "body-parser": "1.20.0", | 30 | | - "commander": "8.3.0", | | 26 | + "@babel/traverse": "7.20.13", | | 27 | + "@swc/core": "1.3.32", | | 28 | + "babel-loader": "9.1.2", | | 29 | + "body-parser": "1.20.1", | | 30 | + "commander": "10.0.0", | 31 | 31 | "copy-webpack-plugin": "^11.0.0", | 32 | | - "css-loader": "6.7.1", | 33 | | - "dotenv": "8.6.0", | | 32 | + "css-loader": "6.7.3", | | 33 | + "dotenv": "16.0.3", | 34 | 34 | "eslint-plugin-jest": "^27.1.6", | 35 | | - "eslint-plugin-nullstack": "^0.0.11", | 36 | | - "express": "4.18.1", | 37 | | - "fs-extra": "10.1.0", | 38 | | - "mini-css-extract-plugin": "2.6.0", | | 35 | + "eslint-plugin-nullstack": "0.0.12", | | 36 | + "express": "4.18.2", | | 37 | + "fs-extra": "11.1.0", | | 38 | + "mini-css-extract-plugin": "2.7.2", | 39 | 39 | "node-fetch": "2.6.7", | 40 | 40 | "nodemon-webpack-plugin": "^4.8.1", | 41 | | - "sass": "1.51.0", | 42 | | - "sass-loader": "8.0.2", | 43 | | - "swc-loader": "0.2.1", | 44 | | - "terser-webpack-plugin": "5.3.1", | 45 | | - "webpack": "5.72.1", | 46 | | - "webpack-dev-server": "4.9.0", | 47 | | - "ws": "7.5.7" | | 41 | + "sass": "1.58.0", | | 42 | + "sass-loader": "13.2.0", | | 43 | + "style-loader": "^3.3.1", | | 44 | + "swc-loader": "0.2.3", | | 45 | + "terser-webpack-plugin": "5.3.6", | | 46 | + "webpack": "5.75.0", | | 47 | + "webpack-dev-server": "4.11.1", | | 48 | + "webpack-hot-middleware": "^2.25.3", | | 49 | + "ws": "8.12.0" | 48 | 50 | } | 49 | 51 | } |
|