appsmith: [Bug]: Working custom widget started failing after latest release.
Is there an existing issue for this?
- I have searched the existing issues
Description
https://react.dev/errors/31?invariant=31&args[]=object with keys {$$typeof, type, key, ref, props}
Started seeing above error which results in a blank widget.
I investigated further and discovered that this was happening due to Layout component from ant design. So replaced it with simple div element.
Then I started seeing following error -
I am not able to debug this at all.
Steps To Reproduce
Here is my custom widget -
import React from 'https://cdn.jsdelivr.net/npm/react@18.2.0/+esm'
import reactDom from 'https://cdn.jsdelivr.net/npm/react-dom@18.2.0/+esm'
import Markdown from 'https://cdn.jsdelivr.net/npm/react-markdown@9.0.1/+esm';
import { Button, Input, Card, Tooltip } from 'https://cdn.jsdelivr.net/npm/antd@5.11.1/+esm'
const SUGGESTED_RESPONSE_ICON = (
<svg xmlns="http://www.w3.org/2000/svg" fill="none" viewBox="0 0 24 24" strokeWidth={1.5} stroke="currentColor" className="size-6" width="20px" height="20px">
<path strokeLinecap="round" strokeLinejoin="round" d="M7.5 8.25h9m-9 3H12m-9.75 1.51c0 1.6 1.123 2.994 2.707 3.227 1.129.166 2.27.293 3.423.379.35.026.67.21.865.501L12 21l2.755-4.133a1.14 1.14 0 0 1 .865-.501 48.172 48.172 0 0 0 3.423-.379c1.584-.233 2.707-1.626 2.707-3.228V6.741c0-1.602-1.123-2.995-2.707-3.228A48.394 48.394 0 0 0 12 3c-2.392 0-4.744.175-7.043.513C3.373 3.746 2.25 5.14 2.25 6.741v6.018Z" />
</svg>
)
const LICENSE_ICON = (
<svg xmlns="http://www.w3.org/2000/svg" fill="none" viewBox="0 0 24 24" width="20px" height="20px" strokeWidth="1.5" stroke="currentColor" className="size-6" color="#000">
<path strokeLinecap="round" strokeLinejoin="round" d="M2.25 18.75a60.07 60.07 0 0 1 15.797 2.101c.727.198 1.453-.342 1.453-1.096V18.75M3.75 4.5v.75A.75.75 0 0 1 3 6h-.75m0 0v-.375c0-.621.504-1.125 1.125-1.125H20.25M2.25 6v9m18-10.5v.75c0 .414.336.75.75.75h.75m-1.5-1.5h.375c.621 0 1.125.504 1.125 1.125v9.75c0 .621-.504 1.125-1.125 1.125h-.375m1.5-1.5H21a.75.75 0 0 0-.75.75v.75m0 0H3.75m0 0h-.375a1.125 1.125 0 0 1-1.125-1.125V15m1.5 1.5v-.75A.75.75 0 0 0 3 15h-.75M15 10.5a3 3 0 1 1-6 0 3 3 0 0 1 6 0Zm3 0h.008v.008H18V10.5Zm-12 0h.008v.008H6V10.5Z" color="#000" />
</svg>
)
const NEW_CONVERSATION_ICON = (
<svg xmlns="http://www.w3.org/2000/svg" fill="none" viewBox="0 0 24 24" stroke-width="1.5" width="20px" height="20px" stroke="currentColor" class="size-6" color="#000">
<path stroke-linecap="round" stroke-linejoin="round" d="M12 4.5v15m7.5-7.5h-15" color="#000" />
</svg>
)
const TRASH_ICON = (
<svg xmlns="http://www.w3.org/2000/svg" fill="none" viewBox="0 0 24 24" stroke-width="1.5" width="20px" height="20px" stroke="currentColor" class="size-6" color="#000">
<path stroke-linecap="round" stroke-linejoin="round" d="m14.74 9-.346 9m-4.788 0L9.26 9m9.968-3.21c.342.052.682.107 1.022.166m-1.022-.165L18.16 19.673a2.25 2.25 0 0 1-2.244 2.077H8.084a2.25 2.25 0 0 1-2.244-2.077L4.772 5.79m14.456 0a48.108 48.108 0 0 0-3.478-.397m-12 .562c.34-.059.68-.114 1.022-.165m0 0a48.11 48.11 0 0 1 3.478-.397m7.5 0v-.916c0-1.18-.91-2.164-2.09-2.201a51.964 51.964 0 0 0-3.32 0c-1.18.037-2.09 1.022-2.09 2.201v.916m7.5 0a48.667 48.667 0 0 0-7.5 0" color="#000" />
</svg>
)
const REFRESH_ICON = (
<svg xmlns="http://www.w3.org/2000/svg" fill="none" viewBox="0 0 24 24" stroke-width="1.5" width="20px" height="20px" stroke="currentColor" class="size-6" color="#000">
<path stroke-linecap="round" stroke-linejoin="round" d="M16.023 9.348h4.992v-.001M2.985 19.644v-4.992m0 0h4.992m-4.993 0 3.181 3.183a8.25 8.25 0 0 0 13.803-3.7M4.031 9.865a8.25 8.25 0 0 1 13.803-3.7l3.181 3.182m0-4.991v4.99" color="#000" />
</svg>
)
const LOADING_SPINNER = (
<svg width="20px" height="20px" class="animate-spin" stroke-width="1.5" viewBox="0 0 24 24" fill="none" xmlns="http://www.w3.org/2000/svg" color="#000"><path d="M11.4563 2.66509C11.6717 2.2034 12.3283 2.2034 12.5437 2.66509L15.4077 8.80229C15.4673 8.93 15.57 9.03266 15.6977 9.09227L21.8349 11.9563C22.2966 12.1717 22.2966 12.8283 21.8349 13.0437L15.6977 15.9077C15.57 15.9673 15.4673 16.07 15.4077 16.1977L12.5437 22.3349C12.3283 22.7966 11.6717 22.7966 11.4563 22.3349L8.59227 16.1977C8.53266 16.07 8.43 15.9673 8.30229 15.9077L2.16509 13.0437C1.7034 12.8283 1.7034 12.1717 2.16509 11.9563L8.30229 9.09227C8.43 9.03266 8.53266 8.93 8.59227 8.80229L11.4563 2.66509Z" stroke="#000" stroke-width="1.5" stroke-linecap="round" stroke-linejoin="round"></path></svg>
)
const SEND = (
<svg width="20px" height="20px" viewBox="0 0 24 24" stroke-width="2" fill="none" xmlns="http://www.w3.org/2000/svg" color="#fff"><path d="M22 12L3 20L6.5625 12L3 4L22 12Z" stroke="#fff" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"></path><path d="M6.5 12L22 12" stroke="#fff" stroke-width="1.5" stroke-linecap="round" stroke-linejoin="round"></path></svg>
)
const USER_ICON = (
<svg width="18px" height="18px" stroke-width="1.5" viewBox="0 0 24 24" fill="none" xmlns="http://www.w3.org/2000/svg" color="#000"><path d="M7 18V17C7 14.2386 9.23858 12 12 12V12C14.7614 12 17 14.2386 17 17V18" stroke="#000" stroke-width="1.5" stroke-linecap="round"></path><path d="M12 12C13.6569 12 15 10.6569 15 9C15 7.34315 13.6569 6 12 6C10.3431 6 9 7.34315 9 9C9 10.6569 10.3431 12 12 12Z" stroke="#000" stroke-width="1.5" stroke-linecap="round" stroke-linejoin="round"></path><circle cx="12" cy="12" r="10" stroke="#000" stroke-width="1.5"></circle></svg>
)
const ASSISTANT_ICON = (
<svg width="18px" height="18px" viewBox="0 0 24 24" stroke-width="1.5" fill="none" xmlns="http://www.w3.org/2000/svg" color="#000"><path d="M8 15C12.8747 15 15 12.949 15 8C15 12.949 17.1104 15 22 15C17.1104 15 15 17.1104 15 22C15 17.1104 12.8747 15 8 15Z" stroke="#000" stroke-width="1.5" stroke-linejoin="round"></path><path d="M2 6.5C5.13376 6.5 6.5 5.18153 6.5 2C6.5 5.18153 7.85669 6.5 11 6.5C7.85669 6.5 6.5 7.85669 6.5 11C6.5 7.85669 5.13376 6.5 2 6.5Z" stroke="#000" stroke-width="1.5" stroke-linejoin="round"></path></svg>
)
const COPY_ICON = (
<svg width="16px" height="16px" viewBox="0 0 24 24" stroke-width="1.3" fill="none" xmlns="http://www.w3.org/2000/svg" color="#000"><path d="M8.5 4H6C4.89543 4 4 4.89543 4 6V20C4 21.1046 4.89543 22 6 22H18C19.1046 22 20 21.1046 20 20V6C20 4.89543 19.1046 4 18 4H15.5" stroke="#000" stroke-width="1.3" stroke-linecap="round"></path><path d="M8 6.4V4.5C8 4.22386 8.22386 4 8.5 4C8.77614 4 9.00422 3.77604 9.05152 3.50398C9.19968 2.65171 9.77399 1 12 1C14.226 1 14.8003 2.65171 14.9485 3.50398C14.9958 3.77604 15.2239 4 15.5 4C15.7761 4 16 4.22386 16 4.5V6.4C16 6.73137 15.7314 7 15.4 7H8.6C8.26863 7 8 6.73137 8 6.4Z" stroke="#000" stroke-width="1.3" stroke-linecap="round"></path></svg>
)
appsmith.onReady(() => {
console.log("App is ready, rendering the App component.");
reactDom.render(<App />, document.getElementById("root"));
});
function App() {
console.log("[App] Initializing component");
const [currentMessage, setCurrentMessage] = React.useState("");
const [ticketId, setTicketId] = React.useState("");
const [loading, setLoading] = React.useState(false);
const [messages, setMessages] = React.useState([]);
const [licenses, setLicenses] = React.useState([]);
React.useEffect(() => {
console.log("[App] useEffect - Initial data fetch", {
modelData: appsmith.model,
currentState: {
messages,
ticketId,
licenses,
loading
}
});
setMessages(appsmith.model?.messages || []);
setTicketId(appsmith.model?.ticketId || "");
setLicenses(appsmith.model?.licenses || []);
appsmith.onModelChange(() => {
console.log("[App] Model changed", {
newModel: appsmith.model,
currentState: {
messages,
ticketId,
licenses,
loading
}
});
setTicketId(appsmith.model?.ticketId || ticketId);
setMessages(appsmith.model?.messages || messages);
setLicenses(appsmith.model?.licenses || licenses);
setLoading(appsmith.model?.loading || loading);
});
}, []);
const sendMessage = () => {
console.log("[App] Attempting to send message", { currentMessage });
if (currentMessage.trim()) {
console.log("[App] Message validated, updating state and triggering event");
setMessages((prevMessages) => {
console.log("[App] Updating messages", {
prevMessages,
newMessage: currentMessage
});
return [...prevMessages, { text: currentMessage, user: true }];
});
appsmith.triggerEvent("sendNewMessage", { message: currentMessage })
setCurrentMessage("");
} else {
console.log("[App] Empty message, skipping send");
}
};
return (
<div className="h-screen relative">
<Navbar ticketId={ticketId} licenses={licenses} />
<div className="flex-grow overflow-y-auto p-2 bg-white">
<Messages messages={messages} loading={loading} />
</div>
<MessageForm value={currentMessage} onChange={setCurrentMessage} onSend={sendMessage} loading={loading} />
</div>
);
}
const Messages = ({ messages, loading }) => {
console.log("[Messages] Rendering", { messages, loading });
const latestMessageRef = React.useRef(null);
React.useEffect(() => {
console.log("[Messages] useEffect - Scroll handling", {
hasRef: !!latestMessageRef.current,
messagesLength: messages?.length
});
if (latestMessageRef.current) {
latestMessageRef.current.scrollIntoView({ behavior: "smooth" });
}
}, [messages, messages?.length]);
return (
<div className="flex flex-col space-y-4 mb-20">
{messages.map((message) => (<MessageBox key={message.id} message={message} />))}
{loading && <LoadingMessage />}
<div className="mb-4" ref={latestMessageRef} />
</div>
)
}
const MessageForm = (props) => {
console.log("[MessageForm] Rendering", props);
const { value, onChange, onSend, loading } = props;
function handleChange(e) {
console.log("[MessageForm] Input change", { value: e.target.value });
e.preventDefault();
onChange(e.target.value);
}
function handleKeyDown(e) {
console.log("[MessageForm] Key pressed", { key: e.key });
if (e.key === 'Enter') {
console.log("[MessageForm] Enter key detected, sending message");
onSend();
e.preventDefault();
}
}
return (
<div
className="flex gap-2 absolute bottom-0 w-full p-2 bg-gray-50 brdt"
>
<Input
className="mb-0"
variant="filled"
size="large"
value={value}
onChange={handleChange}
onKeyPress={handleKeyDown}
placeholder={loading ? "Thinking..." : "Ask your question..."}
disabled={loading}
/>
<Button
onClick={() => {
console.log("[MessageForm] Send button clicked");
onSend();
}}
className={`inline-flex items-center justify-center p-2 text-sm font-medium tracking-wide text-white transition-colors duration-200 bg-purple-600 rounded-md hover:bg-purple-700 focus:ring-2 focus:ring-offset-2 focus:ring-purple-700 focus:shadow-outline focus:outline-none ${loading ? 'opacity-50 cursor-not-allowed' : 'hover:bg-blue-600'
}`}
disabled={loading}
size="large"
>
{!loading ? (SEND) : (LOADING_SPINNER)}
</Button>
</div>
)
};
const Navbar = ({ ticketId, licenses }) => {
console.log("[Navbar] Rendering", { ticketId, licenses });
return (
<div className="flex justify-between gap-2 top-0 w-full p-2 bg-gray-50 brdb">
<div className="flex items-center gap-2 flex-1">
<h1 className="text-base font-semibold flex items-center gap-2">
<img src="https://avatars.githubusercontent.com/u/67620218?s=280&v=4" width="30" />
{ticketId ? `Assisting with ticket #${ticketId}` : "Support Assistant"}
</h1>
{licenses?.length > 0 && (<Tooltip placement="bottom" title="Show Licenses">
<Button variant="filled" onClick={() => appsmith.triggerEvent("showLicenses")} className="border-none p-2 flex items-center bg-gray-50 hover:bg-gray-100">{LICENSE_ICON}</Button>
</Tooltip>)}
</div>
<div className="flex gap-2">
<Tooltip placement="bottom" title="Start New Conversation">
<Button variant="filled" onClick={() => appsmith.triggerEvent("newConversation")} className="border-none p-2 flex items-center bg-gray-50 hover:bg-gray-100">{NEW_CONVERSATION_ICON}</Button>
</Tooltip>
<Tooltip placement="bottom" title="Trash Everything">
<Button variant="filled" onClick={() => appsmith.triggerEvent("trash")} className="border-none p-2 flex items-center bg-gray-50 hover:bg-gray-100">{TRASH_ICON}</Button>
</Tooltip>
</div>
</div>
)
}
const loadingAssistant = (<div className="flex flex-row items-center gap-2 py-2 text-xs">{LOADING_SPINNER} Support Assistant</div>)
const LoadingMessage = () => {
return (
<Card type="inner" size="small" title={loadingAssistant} className="m-0 group flex flex-col mr-10">
<ParsedText>
Thinking...
</ParsedText>
</Card>
)
}
const MessageBox = ({ message }) => {
console.log("[MessageBox] Rendering", { message });
if (message.user) {
return <UserMessage message={message.text} />
} else {
return <AssistantMessage message={message.text} actions={message.actions} />
}
}
const ParsedText = ({ children, props }) => {
return (
<Markdown className={"leading-5 text-wrap overflow-x-auto" + " " + props?.className ?? ""}>
{children}
</Markdown>
)
}
const userTitle = (<div className="flex flex-row items-center gap-2 py-2 text-xs">{USER_ICON} You</div>)
const UserMessage = ({ message }) => {
console.log("[UserMessage] Rendering", { message });
const copyButton = (<CopyButton message={message} />)
return (
<Card type="inner" size="small" title={userTitle} className="m-0 group flex flex-col ml-10" extra={copyButton}>
<ParsedText>
{message}
</ParsedText>
</Card>
)
}
const assistantTitle = (<div className="flex flex-row items-center gap-2 py-2 text-xs">{ASSISTANT_ICON} Support Assistant</div>)
const AssistantMessage = ({ message, actions }) => {
console.log("[AssistantMessage] Rendering", { message, actions });
const copyButton = (<CopyButton message={message} />)
return (
<Card
type="inner"
size="small"
title={assistantTitle}
className="m-0 group flex flex-col mr-10"
extra={copyButton}
actions={
actions?.map((action) => (
<span
key={action.trigger}
onClick={() => {
console.log("[AssistantMessage] Action clicked", { action });
appsmith.triggerEvent(action.trigger, { text: action?.suggestedResponse?.response });
}}
className="flex flex-row justify-center items-center gap-2 text-sm text-gray-500 hover:text-gray-700 cursor-pointer"
>
{SUGGESTED_RESPONSE_ICON} {action.label}
</span>
))
}
>
<ParsedText>
{message}
</ParsedText>
</Card>
)
}
const CopyButton = ({ message }) => {
function handleCopy() {
console.log("[CopyButton] Copying message", { message });
appsmith.triggerEvent("copyText", { text: message });
}
return (
<Button className="p-2 opacity-0 group-hover:opacity-100 border-none bg-transparent hover:bg-gray-100" variant="filled" onClick={handleCopy}>{COPY_ICON}</Button>
)
}
Model -
{
"ticketId": ""
}
Public Sample App
No response
Environment
Production
Severity
High (Blocker to building or releasing)
Issue video log
No response
Version
1.64-snapshot
About this issue
- Original URL
- State: closed
- Created 2 years ago
- Reactions: 4
- Comments: 28 (11 by maintainers)
Family we managed to fix our widget by jumping to react19 these were our imports at the end, sharing if somebody finds them useful.
import * as React from ‘https://esm.sh/react@19’; import * as ReactDom from ‘https://esm.sh/react-dom@19/client’; import { Collapse, Card} from ‘https://esm.sh/antd@5.11.1?bundle’;
import { format } from ‘https://esm.sh/date-fns@2.30.0’; import { AiOutlineArrowRight, AiOutlineRight } from ‘https://esm.sh/react-icons@5.4.0/ai’;
Hey all, its not because of the VPN as the data result is still the same regardless. We found that react@18.2.0 is just automatically routing to get react@18.3.1 in the latest Appsmith version. This seems to be intermittent behaviour too, unsure if its Appsmith itself rerouting it or. If you check network tab when its happening, you can see the +esm call will reroute.
The solution for us was to just point to 18.3.1 in the import for example: import React, { useState, useEffect, useMemo, useCallback } from ‘https://cdn.jsdelivr.net/npm/react@18.3.1/+esm’; import reactDom from ‘https://cdn.jsdelivr.net/npm/react-dom@18.3.1/+esm’;
Now also, the issue of rerouting only triggers when modules like useState and useEffect are used so if you just import react like so: import React from ‘https://cdn.jsdelivr.net/npm/react@18.2.0/+esm’; import reactDom from ‘https://cdn.jsdelivr.net/npm/react-dom@18.2.0/+esm’;
To replicate the issue mentioned just add the Custom Widget in an application and you will easily see since it uses “useState” that it won’t work.
Thanks everyone 😃
cesarCisnerosBirdie Long time no see. I’ve also been having trouble with my Custom widget for the past few days. After a gray screen appears, it either loads too slowly or doesn’t load at all. It’s working fine now, but I think we’ll have to wait and see.
Ya! Working on our end as well!
On Mon, Mar 31, 2025 at 4:41 AM Rahul Barwal @.***> wrote:
So recently JSdeliver updated all the libraries on their end to use react 19.0.0 . If you see this - https://cdn.jsdelivr.net/npm/antd@5.15.0/+esm Notice the code
Previously the library was using 18.2.0. Due to this change, some code starts to fail for antd.
So there is one solution that you can try if you want to use antd. Instead of loading react and antd with jsdeliver, load them with script tags. Your HTML file will look like this now:
now in JS:
to
ReactDOMinstead ofreactDomthat we ship with default code.Now everything should work.
Another solution is don’t use antd and use a different UI library that works with react 19.0.0. The latest version of antd is not working in the custom widget.
Found it…
the usage of
antd@5.11.1 react-icons@5.4.0/ai
now gives you Uncaught SyntaxError: Unexpected end of input
at least in esm.sh
we had to modify to… https://esm.sh/antd@5.25.4?bundle and https://esm.sh/react-icons@5.5.0/ai
@cesarCisnerosBirdie we have not seen any issues recently. Can you share your custom widget code with a screenshot/recording of issue.
Yes, CDN was not working with the VPN connected to Singapore, now using esm.sh import that are working fine in the Singapore region. added these import ``` import React from “https://esm.sh/react@18.2.0\”; import ReactDOM from "https://esm.sh/react-dom@18.2.0\“; import moment from "https://esm.sh/moment@2.30.1\” ````
Thanks for help Rahul!