-
-
Notifications
You must be signed in to change notification settings - Fork 2.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
9 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,14 @@ | ||
import { uneval } from 'devalue'; | ||
|
||
export function serializeProps(props: Record<string, unknown>) { | ||
export function serializeProps(props: Record<string, unknown>, componentName: string) { | ||
// Remove symbolic keys as devalue can't handle them and they don't really make sense to be | ||
// serialized as symbolic keys aren't really equal between the client and server realms | ||
if (Object.getOwnPropertySymbols(props).length) { | ||
props = Object.fromEntries(Object.entries(props).filter(([key]) => typeof key !== 'symbol')); | ||
} | ||
return uneval(props); | ||
try { | ||
return uneval(props); | ||
} catch (e) { | ||
throw new Error(`Unable to serialize props for <${componentName} />`, { cause: e }); | ||
} | ||
} |