Skip to content

Commit 2fbf998

Browse files
Avoid duplicate data in downloaded report file (#6252)
When importing default-exported modules, the JavaScript runtime creates an object with both the properties of the exported object and a 'default' property containing the same data. In the case of the download functionality in the report, this results in the evaluation data being duplicated in the downloaded file (once at the root level and then again inside the 'default' property under the root level). The fix in this commit avoids the problem by serializing the contents of the 'default' property if present and falling back to serializing the outer object otherwise.
1 parent 0e6427c commit 2fbf998

File tree

1 file changed

+9
-1
lines changed
  • src/Libraries/Microsoft.Extensions.AI.Evaluation.Reporting/TypeScript/components

1 file changed

+9
-1
lines changed

src/Libraries/Microsoft.Extensions.AI.Evaluation.Reporting/TypeScript/components/App.tsx

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,8 +56,16 @@ function App() {
5656
const closeSettings = () => setIsSettingsOpen(false);
5757

5858
const downloadDataset = () => {
59+
// check if dataset has a default property that duplicates the content
60+
const containsDefault = 'default' in dataset &&
61+
typeof dataset.default === 'object' &&
62+
dataset.default !== null &&
63+
'scenarioRunResults' in (dataset.default as any);
64+
65+
const dataToSerialize = containsDefault ? dataset.default : dataset;
66+
5967
// create a stringified JSON of the dataset
60-
const dataStr = JSON.stringify(dataset, null, 2);
68+
const dataStr = JSON.stringify(dataToSerialize, null, 2);
6169

6270
// create a link to download the JSON file in the page and click it
6371
const blob = new Blob([dataStr], { type: 'application/json' });

0 commit comments

Comments
 (0)