mirror of
https://github.com/lensapp/lens.git
synced 2025-05-20 05:10:56 +00:00
fix: Don't crash when hovering hotbar menu index
- Remove all uses of React.ReactNode as it is unsafe, replace them with
usages of SafeReactNode which doesn't contain the '{}' type
Signed-off-by: Sebastian Malton <sebastian@malton.name>
This commit is contained in:
1 parent
f13a145a27
commit
9d51ef2aa6
84 files changed
+246
-208
No files matched your search
@@ -17,7 +17,6 @@ export * from "./src/disposer";
|
||||
export * from "./src/formatDuration";
|
||||
export * from "./src/hash-set";
|
||||
export * from "./src/interval";
|
||||
export * from "./src/is-node-falsy";
|
||||
export * from "./src/isMiddleClick";
|
||||
export * from "./src/isReactNode";
|
||||
export * from "./src/iter";
|
||||
|
||||
@@ -1,27 +0,0 @@
|
||||
/**
|
||||
* Copyright (c) OpenLens Authors. All rights reserved.
|
||||
* Licensed under MIT License. See LICENSE in root directory for more information.
|
||||
*/
|
||||
|
||||
import type React from "react";
|
||||
|
||||
/**
|
||||
* Returns `true` if `node` is a falsy value
|
||||
*/
|
||||
export function isNodeFalsy(node: React.ReactNode): boolean {
|
||||
return !isNodeRenderable(node);
|
||||
}
|
||||
|
||||
/**
|
||||
* Return `true` if React would render this
|
||||
*/
|
||||
export function isNodeRenderable(node: React.ReactNode): boolean {
|
||||
return Boolean(node);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the first react node provided that is would be rendered by react
|
||||
*/
|
||||
export function foldNodes(...nodes: React.ReactNode[]): React.ReactNode {
|
||||
return nodes.find(isNodeRenderable);
|
||||
}
|
||||
@@ -3,12 +3,17 @@
|
||||
* Licensed under MIT License. See LICENSE in root directory for more information.
|
||||
*/
|
||||
|
||||
// Type guard for checking valid react node to use in render
|
||||
import type { ReactNode } from "react";
|
||||
import React from "react";
|
||||
import { isObject } from "./type-narrowing";
|
||||
import type { SingleOrMany } from "./types";
|
||||
|
||||
export function isReactNode(node: unknown): node is ReactNode {
|
||||
export type SafeReactNode = React.ReactElement | React.ReactText | boolean | null | undefined | Iterable<SafeReactNode>;
|
||||
|
||||
export function toSafeReactChildrenArray(children: SingleOrMany<SafeReactNode>) {
|
||||
return React.Children.toArray(children) as (Exclude<SafeReactNode, boolean | null | undefined>)[];
|
||||
}
|
||||
|
||||
export function isReactNode(node: unknown): node is SafeReactNode {
|
||||
return (isObject(node) && React.isValidElement(node))
|
||||
|| Array.isArray(node) && node.every(isReactNode)
|
||||
|| node == null
|
||||
|
||||
@@ -95,7 +95,7 @@ export function formatJSONValue(value: unknown): string {
|
||||
/**
|
||||
* This function is a safer version of `JSONPath.value(obj, path)` with untrusted jsonpath strings
|
||||
*
|
||||
* This function will also stringify the value retreived from the object
|
||||
* This function will also stringify the value retrieved from the object
|
||||
*/
|
||||
export function safeJSONPathValue(obj: object, path: string): unknown {
|
||||
try {
|
||||
|
||||
Reference in new issue
Block a user