From 2f7e67a1efa03b3967c195e6413bcadea4972cf5 Mon Sep 17 00:00:00 2001
From: Viktor Andersson <30777521+VIKTORVAV99@users.noreply.github.com>
Date: Mon, 15 Jul 2024 19:59:08 +0200
Subject: [PATCH] optimize_nodesToString (#1765)
---
src/TransWithoutContext.js | 21 ++++++++++++---------
1 file changed, 12 insertions(+), 9 deletions(-)
diff --git a/src/TransWithoutContext.js b/src/TransWithoutContext.js
index 37b51084..9260f315 100644
--- a/src/TransWithoutContext.js
+++ b/src/TransWithoutContext.js
@@ -47,19 +47,22 @@ export const nodesToString = (children, i18nOptions) => {
// expected e.g. lorem
stringNode += `${child}`;
} else if (isValidElement(child)) {
- const childPropsCount = Object.keys(child.props).length;
- const shouldKeepChild = keepArray.indexOf(child.type) > -1;
- const childChildren = child.props.children;
+ const { props, type } = child;
+ const childPropsCount = Object.keys(props).length;
+ const shouldKeepChild = keepArray.indexOf(type) > -1;
+ const childChildren = props.children;
- if (!childChildren && shouldKeepChild && childPropsCount === 0) {
+ if (!childChildren && shouldKeepChild && !childPropsCount) {
// actual e.g. lorem
ipsum
// expected e.g. lorem
ipsum
- stringNode += `<${child.type}/>`;
- } else if (!childChildren && (!shouldKeepChild || childPropsCount !== 0)) {
+ stringNode += `<${type}/>`;
+ } else if (
+ (!childChildren && (!shouldKeepChild || childPropsCount)) ||
+ props.i18nIsDynamicList
+ ) {
// actual e.g. lorem