Skip to content

Commit 1f5ff7d

Browse files
authored
Merge pull request #2027 from redpanda-data/fix/respect-backend-payload-encoding
fix(messages): respect backend payload encoding to prevent precision loss
2 parents 3411003 + b67989a commit 1f5ff7d

File tree

4 files changed

+39
-6
lines changed

4 files changed

+39
-6
lines changed

frontend/bun.lock

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@
4949
"hast": "^1.0.0",
5050
"hast-util-to-jsx-runtime": "^2.3.6",
5151
"js-base64": "^3.7.8",
52+
"json-bigint": "^1.0.0",
5253
"jwt-decode": "^4.0.0",
5354
"lottie-react": "^2.4.1",
5455
"lucide-react": "^0.553.0",
@@ -115,6 +116,7 @@
115116
"@testing-library/jest-dom": "^6.9.1",
116117
"@testing-library/react": "^16.3.0",
117118
"@testing-library/user-event": "^14.6.1",
119+
"@types/json-bigint": "^1.0.4",
118120
"@types/node": "^22.19.1",
119121
"@types/react": "^18.3.26",
120122
"@types/react-beautiful-dnd": "^13.1.8",
@@ -1053,6 +1055,8 @@
10531055

10541056
"@types/http-proxy": ["@types/[email protected]", "", { "dependencies": { "@types/node": "*" } }, "sha512-ED6LB+Z1AVylNTu7hdzuBqOgMnvG/ld6wGCG8wFnAzKX5uyW2K3WD52v0gnLCTK/VLpXtKckgWuyScYK6cSPaw=="],
10551057

1058+
"@types/json-bigint": ["@types/[email protected]", "", {}, "sha512-ydHooXLbOmxBbubnA7Eh+RpBzuaIiQjh8WGJYQB50JFGFrdxW7JzVlyEV7fAXw0T2sqJ1ysTneJbiyNLqZRAag=="],
1059+
10561060
"@types/json-schema": ["@types/[email protected]", "", {}, "sha512-5+fP8P8MFNC+AyZCDxrB2pkZFPGzqQWUzpSeuuVLvm8VMcorNYavBqoFcxK8bQz4Qsbn4oUEEem4wDLfcysGHA=="],
10571061

10581062
"@types/katex": ["@types/[email protected]", "", {}, "sha512-HMwFiRujE5PjrgwHQ25+bsLJgowjGjm5Z8FVSf0N6PwgJrwxH0QxzHYDcKsTfV3wva0vzrpqMTJS2jXPr5BMEQ=="],
@@ -1273,6 +1277,8 @@
12731277

12741278
"big.js": ["[email protected]", "", {}, "sha512-vyL2OymJxmarO8gxMr0mhChsO9QGwhynfuu4+MHTAW6czfq9humCB7rKpUjDd9YUiDPU4mzpyupFSvOClAwbmQ=="],
12751279

1280+
"bignumber.js": ["[email protected]", "", {}, "sha512-Ko0uX15oIUS7wJ3Rb30Fs6SkVbLmPBAKdlm7q9+ak9bbIeFf0MwuBsQV6z7+X768/cHsfg+WlysDWJcmthjsjQ=="],
1281+
12761282
"binary-extensions": ["[email protected]", "", {}, "sha512-Ceh+7ox5qe7LJuLHoY0feh3pHuUDHAcRUeyL2VYghZwfpkNIy/+8Ocg0a3UuSoYzavmylwuLWQOf3hl0jjMMIw=="],
12771283

12781284
"bl": ["[email protected]", "", { "dependencies": { "buffer": "^5.5.0", "inherits": "^2.0.4", "readable-stream": "^3.4.0" } }, "sha512-1W07cM9gS6DcLperZfFSj+bWLtaPGSOHWhPiGzXmvVJbRLdG82sH/Kn8EtW1VqWVA54AKf2h5k5BbnIbwF3h6w=="],
@@ -2035,6 +2041,8 @@
20352041

20362042
"jsesc": ["[email protected]", "", { "bin": { "jsesc": "bin/jsesc" } }, "sha512-/sM3dO2FOzXjKQhJuo0Q173wf2KOo8t4I8vHy6lF9poUp7bKT0/NHE8fPX23PwfhnykfqnC2xRxOnVw5XuGIaA=="],
20372043

2044+
"json-bigint": ["[email protected]", "", { "dependencies": { "bignumber.js": "^9.0.0" } }, "sha512-SiPv/8VpZuWbvLSMtTDU8hEfrZWg/mH/nV/b4o0CYbSxu1UIQPLdwKOCIyLQX+VIPO5vrLX3i8qtqFyhdPSUSQ=="],
2045+
20382046
"json-parse-even-better-errors": ["[email protected]", "", {}, "sha512-xyFwyhro/JEof6Ghe2iz2NcXoj2sloNsWr/XsERDK/oiPCfaNhl5ONfp+jQdAZRQQ0IJWNzH9zIZF7li91kh2w=="],
20392047

20402048
"json-schema": ["[email protected]", "", {}, "sha512-es94M3nTIfsEPisRafak+HDLfHXnKBhV3vU5eqPcS3flIWqcxJWgXHXiey3YrpaNsanY5ei1VoYEbOzijuq9BA=="],

frontend/package.json

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,7 @@
8383
"hast": "^1.0.0",
8484
"hast-util-to-jsx-runtime": "^2.3.6",
8585
"js-base64": "^3.7.8",
86+
"json-bigint": "^1.0.0",
8687
"jwt-decode": "^4.0.0",
8788
"lottie-react": "^2.4.1",
8889
"lucide-react": "^0.553.0",
@@ -148,6 +149,7 @@
148149
"@testing-library/dom": "^10.4.1",
149150
"@testing-library/jest-dom": "^6.9.1",
150151
"@testing-library/react": "^16.3.0",
152+
"@types/json-bigint": "^1.0.4",
151153
"@testing-library/user-event": "^14.6.1",
152154
"@types/node": "^22.19.1",
153155
"@types/react": "^18.3.26",

frontend/src/state/backend-api.ts

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,10 @@ import {
2222
isBakedInTrial,
2323
prettyLicenseType,
2424
} from 'components/license/license-utils';
25+
import JSONBigIntFactory from 'json-bigint';
26+
27+
const JSONBigInt = JSONBigIntFactory({ storeAsString: true });
28+
2529
import { comparer, computed, observable, runInAction, transaction } from 'mobx';
2630
import { ListMessagesRequestSchema } from 'protogen/redpanda/api/console/v1alpha1/list_messages_pb';
2731
import type { TransformMetadata } from 'protogen/redpanda/api/dataplane/v1/transform_pb';
@@ -2928,15 +2932,16 @@ export function createMessageSearch() {
29282932
m.key.payload = keyPayload;
29292933
m.key.normalizedPayload = key?.normalizedPayload;
29302934

2935+
// Only parse JSON payloads with JSONBigInt to preserve large integer precision
29312936
try {
2932-
m.key.payload = JSON.parse(keyPayload);
2937+
m.key.payload = JSONBigInt.parse(keyPayload);
29332938
} catch {
2934-
// no op - payload may not be JSON
2939+
// no op - payload may not be valid JSON
29352940
}
29362941

29372942
m.key.troubleshootReport = key?.troubleshootReport;
29382943
m.key.schemaId = key?.schemaId ?? 0;
2939-
m.keyJson = JSON.stringify(m.key.payload);
2944+
m.keyJson = keyPayload;
29402945
m.key.size = Number(key?.payloadSize);
29412946
m.key.isPayloadTooLarge = key?.isPayloadTooLarge;
29422947

@@ -3007,13 +3012,14 @@ export function createMessageSearch() {
30073012
m.valueJson = valuePayload;
30083013
m.value.isPayloadTooLarge = val?.isPayloadTooLarge;
30093014

3015+
// Only parse JSON payloads with JSONBigInt to preserve large integer precision
30103016
try {
3011-
m.value.payload = JSON.parse(valuePayload);
3017+
m.value.payload = JSONBigInt.parse(valuePayload);
30123018
} catch {
3013-
// no op - payload may not be JSON
3019+
// no op - payload may not be valid JSON
30143020
}
30153021

3016-
m.valueJson = JSON.stringify(m.value.payload);
3022+
m.valueJson = valuePayload;
30173023
m.value.size = Number(val?.payloadSize);
30183024

30193025
this.messages.push(m);

frontend/yarn.lock

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3834,6 +3834,11 @@
38343834
dependencies:
38353835
"@types/node" "*"
38363836

3837+
"@types/json-bigint@^1.0.4":
3838+
version "1.0.4"
3839+
resolved "https://registry.npmjs.org/@types/json-bigint/-/json-bigint-1.0.4.tgz"
3840+
integrity sha512-ydHooXLbOmxBbubnA7Eh+RpBzuaIiQjh8WGJYQB50JFGFrdxW7JzVlyEV7fAXw0T2sqJ1ysTneJbiyNLqZRAag==
3841+
38373842
"@types/json-schema@*", "@types/json-schema@^7.0.15", "@types/json-schema@^7.0.9":
38383843
version "7.0.15"
38393844
resolved "https://registry.npmjs.org/@types/json-schema/-/json-schema-7.0.15.tgz"
@@ -4664,6 +4669,11 @@ big.js@^5.2.2:
46644669
resolved "https://registry.npmjs.org/big.js/-/big.js-5.2.2.tgz"
46654670
integrity sha512-vyL2OymJxmarO8gxMr0mhChsO9QGwhynfuu4+MHTAW6czfq9humCB7rKpUjDd9YUiDPU4mzpyupFSvOClAwbmQ==
46664671

4672+
bignumber.js@^9.0.0:
4673+
version "9.3.1"
4674+
resolved "https://registry.npmjs.org/bignumber.js/-/bignumber.js-9.3.1.tgz"
4675+
integrity sha512-Ko0uX15oIUS7wJ3Rb30Fs6SkVbLmPBAKdlm7q9+ak9bbIeFf0MwuBsQV6z7+X768/cHsfg+WlysDWJcmthjsjQ==
4676+
46674677
binary-extensions@^2.0.0:
46684678
version "2.3.0"
46694679
resolved "https://registry.npmjs.org/binary-extensions/-/binary-extensions-2.3.0.tgz"
@@ -7848,6 +7858,13 @@ jsesc@^3.0.2:
78487858
resolved "https://registry.npmjs.org/jsesc/-/jsesc-3.1.0.tgz"
78497859
integrity sha512-/sM3dO2FOzXjKQhJuo0Q173wf2KOo8t4I8vHy6lF9poUp7bKT0/NHE8fPX23PwfhnykfqnC2xRxOnVw5XuGIaA==
78507860

7861+
json-bigint@^1.0.0:
7862+
version "1.0.0"
7863+
resolved "https://registry.npmjs.org/json-bigint/-/json-bigint-1.0.0.tgz"
7864+
integrity sha512-SiPv/8VpZuWbvLSMtTDU8hEfrZWg/mH/nV/b4o0CYbSxu1UIQPLdwKOCIyLQX+VIPO5vrLX3i8qtqFyhdPSUSQ==
7865+
dependencies:
7866+
bignumber.js "^9.0.0"
7867+
78517868
json-parse-even-better-errors@^2.3.0, json-parse-even-better-errors@^2.3.1:
78527869
version "2.3.1"
78537870
resolved "https://registry.npmjs.org/json-parse-even-better-errors/-/json-parse-even-better-errors-2.3.1.tgz"

0 commit comments

Comments
 (0)