yahoo/react-i13n

An undefined/null element triggers onEnterViewport

Opened this issue · 0 comments

gmp commented

Certainly possible I'm misinterpreting the code, but it appears as if _onEnterViewport is purposefully triggered if/when the tracked element does not exist. See https://github.com/yahoo/react-i13n/blob/master/src/libs/ViewportDetector.js#L56

In practice, I'm also noticing that components who's render return value ends up as null are being tracked as entering the viewport, but this seems counterintuitive.

contrived example:

const ConditionalComponent = (props) => {
    return props.shouldRender ? <div>Yay!</div> : null;
};

const i13nConditionalComponent = createI13nNode(ConditionalComponent);

// triggers viewport as intended when in view
<ConditionalComponent shouldRender />

// still triggers viewport as maybe(?) unintended on init
<ConditionalComponent shouldRender={false} />