Others

How to Fix Adaptive Cards Creating Empty Div Elements in React

Bushra ParveenBushra Parveen Oct 28, 2026 868 views

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.

Fixing Adaptive Cards Creating Empty Div Elements in React
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.
Before you start

Verify the exact versions of the adaptivecards and adaptivecards-templating npm packages installed in your project, as rendering behaviors can vary between SDK releases.

Solution 1Recommended

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.

1
Locate the source array

Find the array in your React component's state or props that contains the objects you are passing to the Adaptive Card templating context.

2
Apply JavaScript filtering

Use the JavaScript .filter() method to remove items that do not meet your specific attributeCode condition before they reach the templating engine.

3
Evaluate the card payload

Pass this newly filtered, clean array into the Template.expand() evaluation context, allowing you to safely remove the $when condition from your card JSON.

Filter the Data Payload Before Templating
Performance Benefit: Filtering data before rendering reduces the processing load on the Adaptive Cards templating engine, often leading to faster component render times.
Free Microsoft Office alternative

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. 1. Download the software: Visit the official WPS Office website and download the appropriate installer for your development operating system.
  2. 2. Install the suite: Run the lightweight installer to quickly set up the Writer, Spreadsheet, and Presentation tools on your machine.
  3. 3. Manage your documentation: Open your existing Microsoft Office files immediately without any conversion, and start managing your project documentation natively.
Fully compatible with Microsoft Office formats (DOCX, XLSX, PPTX) for seamless documentation sharing.Lightweight architecture consumes minimal system memory, leaving more resources for your React development server and IDE.Built-in PDF tools make it incredibly easy to review, annotate, and merge software API documentation.Cross-platform support ensures you can read and write documentation whether you are developing on Windows, macOS, or Linux.
microsoft office alternative - wps office

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.