Skip to content

Commit

Permalink
Fix detection of Backspace and Delay elements
Browse files Browse the repository at this point in the history
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`
  • Loading branch information
jstejada committed Oct 21, 2017
1 parent 85a5698 commit d122bd1
Showing 1 changed file with 4 additions and 4 deletions.
8 changes: 4 additions & 4 deletions src/utils.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
import React from 'react';
import Backspace from './Backspace';
import Delay from './Delay';

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

const name = element.type && element.type.name;
const isNonTypistElement = (
React.isValidElement(element) &&
!(name === 'Delay' || name === 'Backspace')
!(element.type === Delay || element.type === Backspace)
);

if (isNonTypistElement) {
Expand Down

0 comments on commit d122bd1

Please sign in to comment.