From c85646aee7058043cdbcb0110bb7a7e189da9ca6 Mon Sep 17 00:00:00 2001 From: DK-Stern Date: Tue, 1 Mar 2022 21:08:17 +0100 Subject: [PATCH] Fix for issue #1302: "SSR: Duplicated ids in rendered markup, if there are nodes with attributes 'media', 'heights' or 'sizes'" (#1303) * fix duplicated ids * Added transformation test and refactored fix. * Adjusted input.html of transformation test with more realistic example --- .../lib/transformers/ApplyCommonAttributes.js | 1 + .../expected_output.html | 18 ++++++++++++++++++ .../input.html | 11 +++++++++++ 3 files changed, 30 insertions(+) create mode 100644 packages/optimizer/spec/transformers/valid/ServerSideRendering/generates_unique_ids_for_items_with_media_and_ignores_items_with_own_id/expected_output.html create mode 100644 packages/optimizer/spec/transformers/valid/ServerSideRendering/generates_unique_ids_for_items_with_media_and_ignores_items_with_own_id/input.html diff --git a/packages/optimizer/lib/transformers/ApplyCommonAttributes.js b/packages/optimizer/lib/transformers/ApplyCommonAttributes.js index d149589f5..835d7ecbf 100644 --- a/packages/optimizer/lib/transformers/ApplyCommonAttributes.js +++ b/packages/optimizer/lib/transformers/ApplyCommonAttributes.js @@ -219,6 +219,7 @@ class ApplyCommonAttributes { } if (nodeHasBeenTransformed) { node.attribs.id = id; + this.ids.add(id); } else { this.transformedNodesCounter--; } diff --git a/packages/optimizer/spec/transformers/valid/ServerSideRendering/generates_unique_ids_for_items_with_media_and_ignores_items_with_own_id/expected_output.html b/packages/optimizer/spec/transformers/valid/ServerSideRendering/generates_unique_ids_for_items_with_media_and_ignores_items_with_own_id/expected_output.html new file mode 100644 index 000000000..571e09e1a --- /dev/null +++ b/packages/optimizer/spec/transformers/valid/ServerSideRendering/generates_unique_ids_for_items_with_media_and_ignores_items_with_own_id/expected_output.html @@ -0,0 +1,18 @@ + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/packages/optimizer/spec/transformers/valid/ServerSideRendering/generates_unique_ids_for_items_with_media_and_ignores_items_with_own_id/input.html b/packages/optimizer/spec/transformers/valid/ServerSideRendering/generates_unique_ids_for_items_with_media_and_ignores_items_with_own_id/input.html new file mode 100644 index 000000000..d5a617b6f --- /dev/null +++ b/packages/optimizer/spec/transformers/valid/ServerSideRendering/generates_unique_ids_for_items_with_media_and_ignores_items_with_own_id/input.html @@ -0,0 +1,11 @@ + + + + + + + + + + +