From 85611dda8a4011055b028e72a3c95f39b73ae8f9 Mon Sep 17 00:00:00 2001 From: unadlib Date: Mon, 9 May 2022 00:26:17 +0800 Subject: [PATCH 1/2] fix(webpack): use port 7001 instead of 7000 about macOS Monterey port issue --- examples/js-counter/webpack.config.js | 2 +- examples/reactant-share-hybrid/webpack.config.js | 2 +- examples/reactant-share-serviceworker/webpack.config.js | 2 +- examples/reactant-share-sharedtab/webpack.config.js | 2 +- examples/reactant-share-sharedworker/webpack.config.js | 2 +- examples/reactant-share-webrtc/webpack.config.js | 2 +- examples/ts-bookstore/webpack.config.js | 2 +- examples/ts-counter/webpack.config.js | 2 +- .../service-worker/javascript/template/webpack.config.js | 2 +- .../service-worker/typescript/template/webpack.config.js | 2 +- .../templates/shared-tab/javascript/template/webpack.config.js | 2 +- .../templates/shared-tab/typescript/template/webpack.config.js | 2 +- .../shared-worker/javascript/template/webpack.config.js | 2 +- .../shared-worker/typescript/template/webpack.config.js | 2 +- .../templates/web/javascript/template/webpack.config.js | 2 +- .../templates/web/typescript/template/webpack.config.js | 2 +- 16 files changed, 16 insertions(+), 16 deletions(-) diff --git a/examples/js-counter/webpack.config.js b/examples/js-counter/webpack.config.js index 95d9725f7..803694aaa 100644 --- a/examples/js-counter/webpack.config.js +++ b/examples/js-counter/webpack.config.js @@ -41,7 +41,7 @@ module.exports = { devServer: { contentBase: path.join(__dirname, 'dist'), compress: true, - port: 7000, + port: 7001, open: true, }, plugins: [new CopyWebpackPlugin([path.join(__dirname, './src/index.html')])], diff --git a/examples/reactant-share-hybrid/webpack.config.js b/examples/reactant-share-hybrid/webpack.config.js index 6eae13997..aafd48e26 100644 --- a/examples/reactant-share-hybrid/webpack.config.js +++ b/examples/reactant-share-hybrid/webpack.config.js @@ -48,7 +48,7 @@ module.exports = { devServer: { contentBase: path.join(__dirname, 'dist'), compress: true, - port: 7000, + port: 7001, open: true, }, plugins: [ diff --git a/examples/reactant-share-serviceworker/webpack.config.js b/examples/reactant-share-serviceworker/webpack.config.js index d8e030f7c..cb737655e 100644 --- a/examples/reactant-share-serviceworker/webpack.config.js +++ b/examples/reactant-share-serviceworker/webpack.config.js @@ -43,7 +43,7 @@ module.exports = { mode: 'development', devServer: { compress: true, - port: 7000, + port: 7001, open: true, https: true, }, diff --git a/examples/reactant-share-sharedtab/webpack.config.js b/examples/reactant-share-sharedtab/webpack.config.js index 06eb8e447..145e1e463 100644 --- a/examples/reactant-share-sharedtab/webpack.config.js +++ b/examples/reactant-share-sharedtab/webpack.config.js @@ -44,7 +44,7 @@ module.exports = { devServer: { contentBase: path.join(__dirname, 'dist'), compress: true, - port: 7000, + port: 7001, open: true, }, plugins: [new CopyWebpackPlugin([path.join(__dirname, './src/index.html')])], diff --git a/examples/reactant-share-sharedworker/webpack.config.js b/examples/reactant-share-sharedworker/webpack.config.js index a329bb6ae..93da6ccdc 100644 --- a/examples/reactant-share-sharedworker/webpack.config.js +++ b/examples/reactant-share-sharedworker/webpack.config.js @@ -43,7 +43,7 @@ module.exports = { mode: 'development', devServer: { compress: true, - port: 7000, + port: 7001, open: true, }, output: { diff --git a/examples/reactant-share-webrtc/webpack.config.js b/examples/reactant-share-webrtc/webpack.config.js index f01adb495..45bba0ef4 100644 --- a/examples/reactant-share-webrtc/webpack.config.js +++ b/examples/reactant-share-webrtc/webpack.config.js @@ -41,7 +41,7 @@ module.exports = { mode: 'development', devServer: { compress: true, - port: 7000, + port: 7001, open: true, }, output: { diff --git a/examples/ts-bookstore/webpack.config.js b/examples/ts-bookstore/webpack.config.js index 57a7a796a..2ab752f10 100644 --- a/examples/ts-bookstore/webpack.config.js +++ b/examples/ts-bookstore/webpack.config.js @@ -39,7 +39,7 @@ module.exports = { devServer: { contentBase: path.join(__dirname, 'dist'), compress: true, - port: 7000, + port: 7001, open: true, }, plugins: [new CopyWebpackPlugin([path.join(__dirname, './src/index.html')])], diff --git a/examples/ts-counter/webpack.config.js b/examples/ts-counter/webpack.config.js index 1a4b69d7f..d81ac255f 100644 --- a/examples/ts-counter/webpack.config.js +++ b/examples/ts-counter/webpack.config.js @@ -40,7 +40,7 @@ module.exports = { devServer: { contentBase: path.join(__dirname, 'dist'), compress: true, - port: 7000, + port: 7001, open: true, }, plugins: [new CopyWebpackPlugin([path.join(__dirname, './src/index.html')])], diff --git a/packages/reactant-template/templates/service-worker/javascript/template/webpack.config.js b/packages/reactant-template/templates/service-worker/javascript/template/webpack.config.js index 48c315012..076f8aa24 100644 --- a/packages/reactant-template/templates/service-worker/javascript/template/webpack.config.js +++ b/packages/reactant-template/templates/service-worker/javascript/template/webpack.config.js @@ -31,7 +31,7 @@ module.exports = { directory: path.join(__dirname, 'public'), }, compress: true, - port: 7000, + port: 7001, https: true, // TODO: use https://github.com/FiloSottile/mkcert }, plugins: [ diff --git a/packages/reactant-template/templates/service-worker/typescript/template/webpack.config.js b/packages/reactant-template/templates/service-worker/typescript/template/webpack.config.js index cd0048330..a35f374fd 100644 --- a/packages/reactant-template/templates/service-worker/typescript/template/webpack.config.js +++ b/packages/reactant-template/templates/service-worker/typescript/template/webpack.config.js @@ -28,7 +28,7 @@ module.exports = { directory: path.join(__dirname, 'public'), }, compress: true, - port: 7000, + port: 7001, https: true, // TODO: use https://github.com/FiloSottile/mkcert }, plugins: [ diff --git a/packages/reactant-template/templates/shared-tab/javascript/template/webpack.config.js b/packages/reactant-template/templates/shared-tab/javascript/template/webpack.config.js index dfeeb045c..25374777c 100644 --- a/packages/reactant-template/templates/shared-tab/javascript/template/webpack.config.js +++ b/packages/reactant-template/templates/shared-tab/javascript/template/webpack.config.js @@ -28,7 +28,7 @@ module.exports = { directory: path.join(__dirname, 'public'), }, compress: true, - port: 7000, + port: 7001, }, plugins: [ new CopyWebpackPlugin({ diff --git a/packages/reactant-template/templates/shared-tab/typescript/template/webpack.config.js b/packages/reactant-template/templates/shared-tab/typescript/template/webpack.config.js index c81aad089..4e6b49c3c 100644 --- a/packages/reactant-template/templates/shared-tab/typescript/template/webpack.config.js +++ b/packages/reactant-template/templates/shared-tab/typescript/template/webpack.config.js @@ -25,7 +25,7 @@ module.exports = { directory: path.join(__dirname, 'public'), }, compress: true, - port: 7000, + port: 7001, }, plugins: [ new CopyWebpackPlugin({ diff --git a/packages/reactant-template/templates/shared-worker/javascript/template/webpack.config.js b/packages/reactant-template/templates/shared-worker/javascript/template/webpack.config.js index 7ad302845..d0368239e 100644 --- a/packages/reactant-template/templates/shared-worker/javascript/template/webpack.config.js +++ b/packages/reactant-template/templates/shared-worker/javascript/template/webpack.config.js @@ -31,7 +31,7 @@ module.exports = { directory: path.join(__dirname, 'public'), }, compress: true, - port: 7000, + port: 7001, }, plugins: [ new CopyWebpackPlugin({ diff --git a/packages/reactant-template/templates/shared-worker/typescript/template/webpack.config.js b/packages/reactant-template/templates/shared-worker/typescript/template/webpack.config.js index 626451599..908eb1ff9 100644 --- a/packages/reactant-template/templates/shared-worker/typescript/template/webpack.config.js +++ b/packages/reactant-template/templates/shared-worker/typescript/template/webpack.config.js @@ -28,7 +28,7 @@ module.exports = { directory: path.join(__dirname, 'public'), }, compress: true, - port: 7000, + port: 7001, }, plugins: [ new CopyWebpackPlugin({ diff --git a/packages/reactant-template/templates/web/javascript/template/webpack.config.js b/packages/reactant-template/templates/web/javascript/template/webpack.config.js index dfeeb045c..25374777c 100644 --- a/packages/reactant-template/templates/web/javascript/template/webpack.config.js +++ b/packages/reactant-template/templates/web/javascript/template/webpack.config.js @@ -28,7 +28,7 @@ module.exports = { directory: path.join(__dirname, 'public'), }, compress: true, - port: 7000, + port: 7001, }, plugins: [ new CopyWebpackPlugin({ diff --git a/packages/reactant-template/templates/web/typescript/template/webpack.config.js b/packages/reactant-template/templates/web/typescript/template/webpack.config.js index c81aad089..4e6b49c3c 100644 --- a/packages/reactant-template/templates/web/typescript/template/webpack.config.js +++ b/packages/reactant-template/templates/web/typescript/template/webpack.config.js @@ -25,7 +25,7 @@ module.exports = { directory: path.join(__dirname, 'public'), }, compress: true, - port: 7000, + port: 7001, }, plugins: [ new CopyWebpackPlugin({ From 838176b87bc1cd7030857edff8ea3676586693da Mon Sep 17 00:00:00 2001 From: unadlib Date: Mon, 9 May 2022 00:27:18 +0800 Subject: [PATCH 2/2] fix(reacant-share): fix portDetector onClient and onServer issue about async --- packages/reactant-share/src/interfaces.ts | 2 ++ packages/reactant-share/src/portDetector.ts | 34 +++++++++++++++++++++ 2 files changed, 36 insertions(+) diff --git a/packages/reactant-share/src/interfaces.ts b/packages/reactant-share/src/interfaces.ts index bb53f367a..2dcbf6bb0 100644 --- a/packages/reactant-share/src/interfaces.ts +++ b/packages/reactant-share/src/interfaces.ts @@ -15,6 +15,8 @@ import { } from './constants'; import type { RouterChangeNameOptions } from './router'; +export type { Transport } from 'data-transport'; + export type Port = 'server' | 'client'; export interface Transports { diff --git a/packages/reactant-share/src/portDetector.ts b/packages/reactant-share/src/portDetector.ts index 87ff7d574..ae869542e 100644 --- a/packages/reactant-share/src/portDetector.ts +++ b/packages/reactant-share/src/portDetector.ts @@ -15,6 +15,7 @@ import { Port, PortApp, Transports, + Transport, } from './interfaces'; export const PortDetectorOptions = Symbol('PortDetectorOptions'); @@ -116,6 +117,21 @@ export class PortDetector { throw new Error(`'onServer' argument should be a function.`); } this.serverCallbacks.add(callback); + + if ( + this.lastHooks && + this.lastHooks.size > 0 && + this.isServer && + this.transport + ) { + try { + const hook = callback(this.transport); + this.lastHooks.add(hook); + } catch (e) { + console.error(e); + } + } + return () => { this.serverCallbacks.delete(callback); }; @@ -132,6 +148,21 @@ export class PortDetector { throw new Error(`'onClient' argument should be a function.`); } this.clientCallbacks.add(callback); + + if ( + this.lastHooks && + this.lastHooks.size > 0 && + this.isClient && + this.transport + ) { + try { + const hook = callback(this.transport); + this.lastHooks.add(hook); + } catch (e) { + console.error(e); + } + } + return () => { this.clientCallbacks.delete(callback); }; @@ -149,10 +180,13 @@ export class PortDetector { return this.options.transports ?? {}; } + transport?: Transport; + setPort( currentPortApp: PortApp, transport: Required[keyof Transports] ) { + this.transport = transport; if (this.lastHooks) { for (const hook of this.lastHooks) { try {