-
Notifications
You must be signed in to change notification settings - Fork 550
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Unable to render cards in Node.js environments #1274
Comments
Hi @rcasto. We have acknowledged this issue report. Please continue to follow this issue for updates/progress/questions. |
I also stumbled over this issue when trying to implement a JS-based Azure Function rendering adaptive cards to HTML. Using the jsdom-trick that @rcasto thankfully mentioned, I was able to generally "make it work", but it seems TextBlocks are not rendered: the AdaptiveCard
renders to
but without the "Hello World!". Interestingly, also when taking @rcasto second snippet from runkit and running it local it doesn't include the TextBlock. The same issue is described on the following post |
This is not currently a supported scenario; the JS library is designed to work in a browser and not backend environments. That being said, if there is a desire to help make this scenario possible then we're very much open to a community PR to help us make both of these scenarios possible. |
I know this issue has been closed for a while, but I just want let you know text in TextBox is rendered as innerText of an HtmlElement by adaptive card lib. If you use jsdom to mimic the dom environment, innerText is not supported by jsdom as innerText requires a browser engine to layout but apparently jsdom doesn't have any browser engine and they are not willing to support it. The solution is also simple, just to extends the TextBox element to set textContent: class CustomTextBox extends AdaptiveCards.TextBlock{
overrideInternalRender() {
var element = super.overrideInternalRender();
element.textContent = element.innerText;
return element;
}
}
AdaptiveCards.GlobalRegistry.elements.register("TextBlock", CustomTextBox); @rcasto @pauljereb FYI. |
It seems cards cannot be rendered in Node.js environments. The following runkit demonstrates this:
https://runkit.com/rcasto/adaptive-card-nodejs
In the second example you can see the browser globals (window, document, HTMLElement) patched with jsdom. Ideally the adaptivecards library would not reference browser globals such as document, and window directly and would use jsdom or an equivalent as a substitute for them in Node.js environments.
The text was updated successfully, but these errors were encountered: