From c67f9abadc3c6824d9acbe4edf2f90932e73344b Mon Sep 17 00:00:00 2001
From: Viktor Andersson <30777521+VIKTORVAV99@users.noreply.github.com>
Date: Mon, 15 Jul 2024 18:56:25 +0200
Subject: [PATCH] optimize_nodesToString
---
src/TransWithoutContext.js | 21 ++++++++++++---------
1 file changed, 12 insertions(+), 9 deletions(-)
diff --git a/src/TransWithoutContext.js b/src/TransWithoutContext.js
index 37b51084c..9260f315d 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