mirror of
https://github.com/webstudio-is/webstudio.git
synced 2026-11-09 05:26:24 +09:00
fix: settings panel breaks when resource url is an expression (#3353)
JSON.parse is not safe to parse expressions. Better execute it with try/catch.
This commit is contained in:
1 parent
483b943625
commit
ce8298bf9f
1 file changed
+13
-3
@@ -33,7 +33,11 @@ import {
|
||||
Tooltip,
|
||||
theme,
|
||||
} from "@webstudio-is/design-system";
|
||||
import { isLocalResource, transpileExpression } from "@webstudio-is/sdk";
|
||||
import {
|
||||
executeExpression,
|
||||
isLocalResource,
|
||||
transpileExpression,
|
||||
} from "@webstudio-is/sdk";
|
||||
import type { DataSource } from "@webstudio-is/sdk";
|
||||
import {
|
||||
ExpressionEditor,
|
||||
@@ -388,7 +392,9 @@ const VariablePanel = forwardRef<
|
||||
const [variableType, setVariableType] = useState<VariableType>(() => {
|
||||
if (
|
||||
variable?.type === "resource" &&
|
||||
isLocalResource(JSON.parse(resources.get(variable.resourceId)?.url ?? ""))
|
||||
isLocalResource(
|
||||
String(executeExpression(resources.get(variable.resourceId)?.url) ?? "")
|
||||
)
|
||||
) {
|
||||
return "system-resource";
|
||||
}
|
||||
@@ -642,7 +648,11 @@ export const VariablePopoverTrigger = forwardRef<
|
||||
variable?.type === "resource" && (
|
||||
<>
|
||||
{isLocalResource(
|
||||
JSON.parse(resources.get(variable.resourceId)?.url ?? "")
|
||||
String(
|
||||
executeExpression(
|
||||
resources.get(variable.resourceId)?.url
|
||||
) ?? ""
|
||||
)
|
||||
) === false && (
|
||||
<Tooltip
|
||||
content="Copy resource as cURL command"
|
||||
|
||||
Reference in new issue
Block a user