How to Fix Adaptive Cards Creating Empty Div Elements in React
Question details
The user needs to resolve an issue where an Adaptive Card renders empty HTML structures and blank spaces in a React application despite using conditional logic.

- Product
- Adaptive Cards SDK
- Device & OS
- not provided
- Scenario
- Rendering a data-bound Adaptive Card using adaptivecards-templating in a React frontend where certain array items should be hidden based on a condition.
- Observed behavior
- The templating engine evaluates the $when condition but still outputs empty div elements and blank spaces in the DOM for items that fail the attributeCode condition.
Verify the exact versions of the adaptivecards and adaptivecards-templating npm packages installed in your project, as rendering behaviors can vary between SDK releases.
Filter the Data Payload Before Templating
Pre-filtering your data array in React before passing it to the Adaptive Cards templating engine prevents the SDK from generating empty DOM nodes for hidden items.
The Adaptive Cards templating engine sometimes evaluates the $when condition by hiding the content but leaving the structural container intact. Handling this logic within your React application's data preparation phase ensures cleaner DOM output.
Find the array in your React component's state or props that contains the objects you are passing to the Adaptive Card templating context.
Use the JavaScript .filter() method to remove items that do not meet your specific attributeCode condition before they reach the templating engine.
Pass this newly filtered, clean array into the Template.expand() evaluation context, allowing you to safely remove the $when condition from your card JSON.

Escalate to Official Developer Communities
Because this is a specific React and Adaptive Cards templating SDK rendering issue, submitting a bug report to the official developer channels can yield a direct patch or workaround.
Boost Your Development Workflow with WPS Office
While troubleshooting React and Adaptive Cards integration issues, you need a reliable suite to write API documentation, track bugs in spreadsheets, and outline application architecture. WPS Office is a lightweight, highly compatible alternative to Microsoft Office that easily handles all your documentation needs.
- 1. Download the software: Visit the official WPS Office website and download the appropriate installer for your development operating system.
- 2. Install the suite: Run the lightweight installer to quickly set up the Writer, Spreadsheet, and Presentation tools on your machine.
- 3. Manage your documentation: Open your existing Microsoft Office files immediately without any conversion, and start managing your project documentation natively.

Frequently Asked Questions
Why does the $when condition leave empty div elements in Adaptive Cards?
Depending on the specific version of the adaptivecards-templating SDK, the engine may process the condition by dropping the inner content but retaining the structural container in the layout. This results in empty div tags being rendered in the DOM.
Is this issue related to SharePoint web parts?
No. While Adaptive Cards are often used in SharePoint integrations, an issue specifically related to custom React components and the templating SDK is a pure development issue, not a native SharePoint bug.
Where is the best place to report an Adaptive Cards templating bug?
The most effective place to report a rendering bug or unexpected templating behavior is the official Microsoft AdaptiveCards GitHub repository, as it is monitored directly by the SDK maintainers.
Can I use Adaptive Cards in React without the templating package?
Yes. You can dynamically build your JSON payload using standard JavaScript objects and React state logic before passing it to the base adaptivecards renderer, completely bypassing the need for the adaptivecards-templating package.




