Browse Source

feat: deprecate `ipcRenderer.sendTo()` (#39091)

* feat: deprecate ipcRenderer.sendTo()

* docs: add _Deprecated_ to ipcRenderer.sendTo()
Milan Burda 1 year ago
parent
commit
ada8eb33b2

+ 1 - 1
docs/api/ipc-renderer.md

@@ -192,7 +192,7 @@ ipcMain.on('port', (e, msg) => {
 For more information on using `MessagePort` and `MessageChannel`, see the [MDN
 documentation](https://developer.mozilla.org/en-US/docs/Web/API/MessageChannel).
 
-### `ipcRenderer.sendTo(webContentsId, channel, ...args)`
+### `ipcRenderer.sendTo(webContentsId, channel, ...args)` _Deprecated_
 
 * `webContentsId` number
 * `channel` string

+ 1 - 1
docs/api/structures/ipc-renderer-event.md

@@ -4,5 +4,5 @@
 * `senderId` Integer - The `webContents.id` that sent the message, you can call `event.sender.sendTo(event.senderId, ...)` to reply to the message, see [ipcRenderer.sendTo][ipc-renderer-sendto] for more information. This only applies to messages sent from a different renderer. Messages sent directly from the main process set `event.senderId` to `0`.
 * `ports` [MessagePort][][] - A list of MessagePorts that were transferred with this message
 
-[ipc-renderer-sendto]: ../ipc-renderer.md#ipcrenderersendtowebcontentsid-channel-args
+[ipc-renderer-sendto]: ../ipc-renderer.md#ipcrenderersendtowebcontentsid-channel-args-deprecated
 [MessagePort]: https://developer.mozilla.org/en-US/docs/Web/API/MessagePort

+ 4 - 0
docs/breaking-changes.md

@@ -21,6 +21,10 @@ macOS 10.13 (High Sierra) and macOS 10.14 (Mojave) are no longer supported by [C
 Older versions of Electron will continue to run on these operating systems, but macOS 10.15 (Catalina)
 or later will be required to run Electron v27.0.0 and higher.
 
+### Deprecated: `ipcRenderer.sendTo()`
+
+The `ipcRenderer.sendTo()` API has been deprecated. It should be replaced by setting up a [`MessageChannel`](tutorial/message-ports.md#setting-up-a-messagechannel-between-two-renderers) between the renderers.
+
 ## Planned Breaking API Changes (25.0)
 
 ### Deprecated: `protocol.{register,intercept}{Buffer,String,Stream,File,Http}Protocol`

+ 3 - 0
filenames.auto.gni

@@ -143,6 +143,7 @@ auto_filenames = {
   sandbox_bundle_deps = [
     "lib/common/api/native-image.ts",
     "lib/common/define-properties.ts",
+    "lib/common/deprecate.ts",
     "lib/common/ipc-messages.ts",
     "lib/common/web-view-methods.ts",
     "lib/common/webpack-globals-provider.ts",
@@ -268,6 +269,7 @@ auto_filenames = {
     "lib/common/api/native-image.ts",
     "lib/common/api/shell.ts",
     "lib/common/define-properties.ts",
+    "lib/common/deprecate.ts",
     "lib/common/init.ts",
     "lib/common/ipc-messages.ts",
     "lib/common/reset-search-paths.ts",
@@ -306,6 +308,7 @@ auto_filenames = {
     "lib/common/api/native-image.ts",
     "lib/common/api/shell.ts",
     "lib/common/define-properties.ts",
+    "lib/common/deprecate.ts",
     "lib/common/init.ts",
     "lib/common/ipc-messages.ts",
     "lib/common/reset-search-paths.ts",

+ 2 - 0
lib/renderer/api/ipc-renderer.ts

@@ -1,4 +1,5 @@
 import { EventEmitter } from 'events';
+import * as deprecate from '@electron/internal/common/deprecate';
 
 const { ipc } = process._linkedBinding('electron_renderer_ipc');
 
@@ -18,6 +19,7 @@ ipcRenderer.sendToHost = function (channel, ...args) {
 };
 
 ipcRenderer.sendTo = function (webContentsId, channel, ...args) {
+  deprecate.warnOnce('ipcRenderer.sendTo');
   return ipc.sendTo(webContentsId, channel, args);
 };