Skip to content

Commit d122bd1

Browse files
committed
Fix detection of Backspace and Delay elements
Previously, during `extractTextFromElement` and `cloneElementWithSpecifiedTextAtIndex`, the code would try to determine if an element it was visiting was a `Backspace` or a `Delay` element by checking `element.type.name`. This worked fine most of the time, but if the code was minified, `element.type.name` was no longer `Backspace` or `Delay` because the name of those Components had been changed after minification. In order to fix this, check the reference to the type (`element.type`) instead of checking `element.type.name`
1 parent 85a5698 commit d122bd1

File tree

1 file changed

+4
-4
lines changed

1 file changed

+4
-4
lines changed

src/utils.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
import React from 'react';
2+
import Backspace from './Backspace';
3+
import Delay from './Delay';
24

35
export const sleep = (val) => new Promise((resolve) => (
46
val != null ? setTimeout(resolve, val) : resolve()
@@ -38,8 +40,7 @@ export function extractTextFromElement(element) {
3840
while (stack.length > 0) {
3941
const current = stack.pop();
4042
if (React.isValidElement(current)) {
41-
const name = current.type && current.type.name;
42-
if (name === 'Backspace' || name === 'Delay') {
43+
if (current.type === Backspace || current.type === Delay) {
4344
// If it is a `Backspace` or `Delay` element, we want to keep it in our
4445
// `textLines` state. These will serve as markers when updating the
4546
// state of the text
@@ -85,10 +86,9 @@ function cloneElementWithSpecifiedTextAtIndex(element, textLines, textIdx) {
8586
return child;
8687
};
8788

88-
const name = element.type && element.type.name;
8989
const isNonTypistElement = (
9090
React.isValidElement(element) &&
91-
!(name === 'Delay' || name === 'Backspace')
91+
!(element.type === Delay || element.type === Backspace)
9292
);
9393

9494
if (isNonTypistElement) {

0 commit comments

Comments
 (0)