{"record":{"id":"3b9ad9aa3b007bcb","repo":"quasarframework/quasar","slug":"connection-with-port-name-already-exists-dis","errorCode":null,"errorMessage":"Connection with \"${port.name}\" already exists. Disconnecting the previous one and connecting the new one.","messagePattern":"Connection with \"(.+?)\" already exists\\. Disconnecting the previous one and connecting the new one\\.","errorType":"console","errorClass":null,"httpStatus":null,"severity":"warning","filePath":"app-vite/exports/bex/private/bex-bridge.js","lineNumber":129,"sourceCode":"      })\n\n      return\n    }\n\n    /**\n     * Else we're the background script\n     */\n\n    this.isConnected = true\n    const onPacket = this.#onPacket.bind(this)\n\n    runtime.onConnect.addListener(port => {\n      // if it's not a bridge port on the other end,\n      // then ignore it\n      if (!portNameRE.test(port.name)) return\n\n      if (this.portMap[port.name] !== void 0) {\n        this.warn(\n          `Connection with \"${port.name}\" already exists.` +\n            ' Disconnecting the previous one and connecting the new one.'\n        )\n        this.portMap[port.name].disconnect()\n        this.#cleanupPort(port.name)\n      }\n\n      this.portMap[port.name] = port\n\n      port.onMessage.addListener(onPacket)\n      port.onDisconnect.addListener(() => {\n        port.onMessage.removeListener(onPacket)\n        this.#cleanupPort(port.name)\n        this.log(`Closed connection with ${port.name}.`)\n        this.#onPortChange({ removed: port.name })\n      })\n\n      this.log(`Opened connection with ${port.name}.`)","sourceCodeStart":111,"sourceCodeEnd":147,"githubUrl":"https://github.com/quasarframework/quasar/blob/4841521b5f635a971eb9e2710e5542efd194691b/app-vite/exports/bex/private/bex-bridge.js#L111-L147","documentation":"The BexBridge detected a second runtime.connect() from the same named port context while an existing connection with that name is still open. It warns, disconnects the stale port, cleans it up, and connects the new one. This is a self-healing warning, not a thrown exception.","triggerScenarios":"Calling bridge.connect (or the content/background script init) twice with the same port name without disconnecting first, e.g. on hot module reload, service worker restart, or double-invoked setup code.","commonSituations":"Vite HMR reloading a content script while the background keeps the old port; a browser extension service worker waking up and re-running connection setup; accidental duplicate BexBridge instantiation in both content script contexts.","solutions":["Ensure connect() is called only once per port name (guard setup code against re-execution).","Call bridge.disconnect(portName) before reconnecting with the same name.","On HMR, add an cleanup handler that disconnects the previous port before the module re-runs.","Verify you don't construct two BexBridge instances sharing the same port name."],"exampleFix":"// before\nconst bridge = new Bridge('content-script')\nbridge.send('hello') // re-run on HMR -> duplicate port\n// after\nif (!window.__bexBridge) {\n  window.__bexBridge = new Bridge('content-script')\n}\nconst bridge = window.__bexBridge","handlingStrategy":"validation","validationCode":"if (typeof portName === 'string' && portName.length > 0 && !connectedPorts.has(portName)) {\n  bridge.connect(portName)\n  connectedPorts.add(portName)\n}","typeGuard":"const isValidPortName = (n) => typeof n === 'string' && n.length > 0","tryCatchPattern":null,"preventionTips":["Instantiate the bridge once per context (module singleton).","Disconnect on teardown/HMR before reconnecting.","Use unique port names per script context."],"tags":["bex","extension","port-connection","duplicate-connection"],"backgroundTag":"duplicate-port-connection","analyzedSha":"4841521b5f635a971eb9e2710e5542efd194691b","analyzedAt":"2026-08-30T01:13:14.944Z","schemaVersion":2},"datasetVersion":"2026-08-30T03:17:51.788Z"}