From 6b768085803a49882e7036e4358b52d1972ecc7c Mon Sep 17 00:00:00 2001 From: Matt Kane Date: Sun, 28 Apr 2024 11:55:13 +0100 Subject: [PATCH] fix(react): handle fetchpriority vs fetchPriority (#644) lolsob --- packages/react/src/camelize.ts | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/packages/react/src/camelize.ts b/packages/react/src/camelize.ts index 3c116908..9cb8ca0c 100644 --- a/packages/react/src/camelize.ts +++ b/packages/react/src/camelize.ts @@ -1,9 +1,15 @@ import type { HTMLAttributes } from "react"; +import * as React from "react"; + const nestedKeys = new Set(["style"]); + +export const isNewReact = "use" in React; + const fixedMap: Record = { srcset: "srcSet", - fetchpriority: "fetchPriority" + fetchpriority: isNewReact ? "fetchPriority" : "fetchpriority", }; + const camelize = (key: string) => { if (key.startsWith("data-") || key.startsWith("aria-")) { return key; @@ -14,12 +20,12 @@ const camelize = (key: string) => { }; export function camelizeProps>( - props: TObject + props: TObject, ): TObject { return Object.fromEntries( Object.entries(props).map(([k, v]) => [ camelize(k), nestedKeys.has(k) && v && typeof v !== "string" ? camelizeProps(v) : v, - ]) + ]), ) as TObject; }