From 630ac4e7223b4df4dde5f5866f72cc03f9526890 Mon Sep 17 00:00:00 2001 From: Andrew Clark Date: Wed, 20 Sep 2023 16:07:33 -0400 Subject: [PATCH] Implement createFastHash for Bun In Bun builds, createFastHash uses Bun.hash. See: https://bun.sh/docs/api/hashing#bun-hash --- packages/react-server/src/ReactServerStreamConfigBun.js | 4 +++- scripts/flow/environment.js | 6 ++++++ 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/packages/react-server/src/ReactServerStreamConfigBun.js b/packages/react-server/src/ReactServerStreamConfigBun.js index be53fb9d01dc9..276c7f59e490a 100644 --- a/packages/react-server/src/ReactServerStreamConfigBun.js +++ b/packages/react-server/src/ReactServerStreamConfigBun.js @@ -7,6 +7,8 @@ * @flow */ +/* global Bun */ + type BunReadableStreamController = ReadableStreamController & { end(): mixed, write(data: Chunk | BinaryChunk): void, @@ -98,5 +100,5 @@ export function closeWithError(destination: Destination, error: mixed): void { } export function createFastHash(input: string): string | number { - return input; + return Bun.hash(input); } diff --git a/scripts/flow/environment.js b/scripts/flow/environment.js index 18ba25264138e..7f3996de04fd8 100644 --- a/scripts/flow/environment.js +++ b/scripts/flow/environment.js @@ -281,3 +281,9 @@ declare module 'node:worker_threads' { port2: MessagePort; } } + +declare var Bun: { + hash( + input: string | $TypedArray | DataView | ArrayBuffer | SharedArrayBuffer, + ): number, +};