From f706db3cf4cab67391aaa40fff4b6165597d814f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rickard=20Lund=C3=A9n?= Date: Thu, 25 Oct 2018 19:41:02 +0300 Subject: [PATCH] fix: Compare socket event data using lodash's isEqual instead of indexOf (#1061) Using indexOf will return false when comparing identical objects with different references. This in turn breaks feathers-sync since it creates a new object using JSON.parse, meaning that data won't properly sent out when for example patching multiple rows at once. --- packages/transport-commons/lib/socket/utils.js | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/packages/transport-commons/lib/socket/utils.js b/packages/transport-commons/lib/socket/utils.js index 43106c556c..26e9224422 100644 --- a/packages/transport-commons/lib/socket/utils.js +++ b/packages/transport-commons/lib/socket/utils.js @@ -1,5 +1,6 @@ const errors = require('@feathersjs/errors'); const debug = require('debug')('@feathersjs/transport-commons'); +const { isEqual } = require('lodash'); const paramsPositions = exports.paramsPositions = { find: 0, @@ -46,7 +47,7 @@ exports.getDispatcher = function (emit, socketKey) { // If we are getting events from an array but try to dispatch individual data // try to get the individual item to dispatch from the correct index. if (!Array.isArray(data) && Array.isArray(context.result) && Array.isArray(result)) { - result = result[context.result.indexOf(data)]; + result = context.result.find(resultData => isEqual(resultData, data)); } debug(`Dispatching '${eventName}' to Socket ${socket.id} with`, result);