@@ -40038,9 +40038,9 @@ class BraintreeClientApi {
4003840038 } = _ref,
4003940039 callbacks = _objectWithoutProperties(_ref, ["authorization", "styles", "onAuthorizationSuccess"]);
4004040040
40041- this.fields = {} ;
40041+ this.fields = Object.create(null) ;
4004240042 this._nextFieldId = 0;
40043- this.fieldHandlers = {} ;
40043+ this.fieldHandlers = Object.create(null) ;
4004440044 this.styles = styles || {};
4004540045 this.wrapperHandlers = callbacks || {};
4004640046 this.setAuthorization(authorization, onAuthorizationSuccess);
@@ -40050,6 +40050,15 @@ class BraintreeClientApi {
4005040050 if (!authorization && this.authorization) {
4005140051 this.teardown();
4005240052 } else if (authorization && authorization !== this.authorization) {
40053+ // fields have not yet checked in, delay setting so they can register
40054+ if (0 === Object.keys(this.fields).length && !this.pendingAuthTimer) {
40055+ this.pendingAuthTimer = setTimeout(() => {
40056+ this.pendingAuthTimer = null;
40057+ this.setAuthorization(authorization, onAuthorizationSuccess);
40058+ }, 5);
40059+ return;
40060+ }
40061+
4005340062 if (this.authorization) {
4005440063 this.teardown();
4005540064 }
@@ -40117,6 +40126,11 @@ class BraintreeClientApi {
4011740126 if (this.hostedFields) {
4011840127 this.hostedFields.teardown();
4011940128 }
40129+
40130+ if (this.pendingAuthTimer) {
40131+ clearTimeout(this.pendingAuthTimer);
40132+ this.pendingAuthTimer = null;
40133+ }
4012040134 }
4012140135
4012240136 checkInField(_ref2) {
@@ -40133,22 +40147,24 @@ class BraintreeClientApi {
4013340147 } = _ref2,
4013440148 handlers = _objectWithoutProperties(_ref2, ["formatInput", "maxlength", "minlength", "placeholder", "select", "type", "prefill", "id", "rejectUnsupportedCards"]);
4013540149
40136- this.fieldHandlers[type] = handlers;
40137- this.fields[type] = {
40138- formatInput,
40139- maxlength,
40140- minlength,
40141- placeholder,
40142- select,
40143- prefill,
40144- selector: "#".concat(id)
40145- };
40150+ var onRenderComplete = () => {
40151+ this.fieldHandlers[type] = handlers;
40152+ this.fields[type] = {
40153+ formatInput,
40154+ maxlength,
40155+ minlength,
40156+ placeholder,
40157+ select,
40158+ prefill,
40159+ selector: "#".concat(id)
40160+ };
4014640161
40147- if ('number' === type && rejectUnsupportedCards) {
40148- this.fields.number.rejectUnsupportedCards = true;
40149- }
40162+ if ('number' === type && rejectUnsupportedCards) {
40163+ this.fields.number.rejectUnsupportedCards = true;
40164+ }
40165+ };
4015040166
40151- return id ;
40167+ return [id, onRenderComplete] ;
4015240168 }
4015340169
4015440170 focusField(fieldType, cb) {
@@ -40304,6 +40320,11 @@ __webpack_require__.r(__webpack_exports__);
4030440320
4030540321
4030640322class BraintreeHostedField extends react__WEBPACK_IMPORTED_MODULE_0___default.a.Component {
40323+ constructor() {
40324+ super(...arguments);
40325+ this.state = {};
40326+ }
40327+
4030740328 focus() {
4030840329 this.context.braintreeApi.focusField(this.props.type);
4030940330 }
@@ -40317,7 +40338,10 @@ class BraintreeHostedField extends react__WEBPACK_IMPORTED_MODULE_0___default.a.
4031740338 }
4031840339
4031940340 componentDidMount() {
40320- this.fieldId = this.context.braintreeApi.checkInField(this.props);
40341+ var [fieldId, onRenderComplete] = this.context.braintreeApi.checkInField(this.props);
40342+ this.setState({
40343+ fieldId
40344+ }, onRenderComplete);
4032140345 }
4032240346
4032340347 get className() {
@@ -40331,8 +40355,16 @@ class BraintreeHostedField extends react__WEBPACK_IMPORTED_MODULE_0___default.a.
4033140355 }
4033240356
4033340357 render() {
40358+ var {
40359+ fieldId
40360+ } = this.state;
40361+
40362+ if (!fieldId) {
40363+ return null;
40364+ }
40365+
4033440366 return react__WEBPACK_IMPORTED_MODULE_0___default.a.createElement("div", {
40335- id: this. fieldId,
40367+ id: fieldId,
4033640368 className: this.className
4033740369 });
4033840370 }
0 commit comments