From 810c343614795dd732a4ea8e97fe643fb73c97a1 Mon Sep 17 00:00:00 2001 From: Tom Kirkpatrick Date: Thu, 14 Nov 2019 10:17:09 +0100 Subject: [PATCH] fix(grpc): ensure that protobuf has Long support --- renderer/workers/grpc.worker.js | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/renderer/workers/grpc.worker.js b/renderer/workers/grpc.worker.js index a95cb3b1663..31bbe89f906 100644 --- a/renderer/workers/grpc.worker.js +++ b/renderer/workers/grpc.worker.js @@ -1,6 +1,18 @@ /* eslint-disable no-restricted-globals */ import { expose } from 'comlinkjs' +import * as Protobuf from 'protobufjs' +import Long from 'long' import ZapGrpc from '@zap/services/grpc/grpc' +// Protobuf assumes that long.js is either available on the global scope or available to be required. However, when +// used from the context of one of our web workers neither of these assumptions is true. In order to ensure that Long +// support is available in protobuf we manually configure protobuf here, before it is used. +// +// See https://github.com/protobufjs/protobuf.js#browserify-integration +// +// This ensures that large numbers (such as those returned from chan_id props) can be properly handled without rounding. +Protobuf.util.Long = Long +Protobuf.configure() + expose(ZapGrpc, self)