Skip to content

Commit b6ed0f4

Browse files
Update content-gen/src/app/frontend/src/App.tsx
Accepted the Suggestion by Copilot Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
1 parent 4bafc33 commit b6ed0f4

File tree

1 file changed

+5
-2
lines changed
  • content-gen/src/app/frontend/src

1 file changed

+5
-2
lines changed

content-gen/src/app/frontend/src/App.tsx

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -363,9 +363,12 @@ function App() {
363363
// Replace old color/product name in text_content when switching products
364364
const oldName = selectedProducts[0]?.product_name;
365365
const newName = mentionedProduct?.product_name;
366+
const nameRegex = oldName
367+
? new RegExp(oldName.replace(/[.*+?^${}()|[\]\\]/g, '\\$&'), 'gi')
368+
: undefined;
366369
const swapName = (s?: string) => {
367-
if (!s || !oldName || !newName || oldName === newName) return s;
368-
return s.replace(new RegExp(oldName.replace(/[.*+?^${}()|[\]\\]/g, '\\$&'), 'gi'), newName);
370+
if (!s || !oldName || !newName || oldName === newName || !nameRegex) return s;
371+
return s.replace(nameRegex, () => newName);
369372
};
370373
const tc = generatedContent.text_content;
371374

0 commit comments

Comments
 (0)