-
Type:
Bug
-
Resolution: Unresolved
-
Priority:
Low
-
Component/s: Forge - Function invocation
-
Minor
-
M
Issue Summary
If we have a resolver function return `undefined` value, then at the frontend invoke function the value received is and empty JOSN object "{}".
The issue is that `undefined` is a falsey value and an empty JOSN object is a truthly value.
Please make the return type of the resolver function more explicit to avoid confusion.
Steps to reproduce
Create a simple resolver function and return `undefined`
const resolver = new Resolver(); resolver.define("returnUndefined", ({ context }) => { return undefined. }); export const handler = resolver.getDefinitions();
And, call the resolver function with invoke
import React, { useEffect, useState } from "react"; import { events, invoke } from "@forge/bridge"; function App() { const [data, setData] = useState(null); const handleFetchSuccess = (data) => { setData(data); }; const handleFetchError = () => { console.error("Failed to get label"); }; useEffect(() => { const resolver = async () => invoke("returnUndefined"); checkLicense().then(handleFetchSuccess).catch(handleFetchError); const subscribeForIssueChangedEvent = () => events.on("JIRA_ISSUE_CHANGED", () => { resolver().then(handleFetchSuccess).catch(handleFetchError); }); const subscription = subscribeForIssueChangedEvent(); return () => { subscription.then((subscription) => subscription.unsubscribe()); }; }, []); return ( <div> <span>Resolver Response:</span> <div>{JSON.stringify(data)}</div> </div> ); } export default App;
Expected Result
here `data` should be a falsey value or `undefined`
Actual Result
`data` is "{}" which is a truthly value
Workaround
We need to make sure the return from resolver is valid JSON type. `undefined` is not a valid JSON type by ECMA standard.
For example, we can do this.
return !!undefined // this'll return false
- causes
-
ECOHELP-39490 Loading...
- relates to
-
TOOT-3192 Loading...