diff --git a/src/components/Template.js b/src/components/Template.js index 1dd2593028..9af81c7676 100644 --- a/src/components/Template.js +++ b/src/components/Template.js @@ -1,13 +1,13 @@ import React from 'react'; +import hogan from 'hogan.js'; import curry from 'lodash/curry'; import cloneDeep from 'lodash/cloneDeep'; import mapValues from 'lodash/mapValues'; - -import hogan from 'hogan.js'; - import isEqual from 'lodash/isEqual'; +import {isReactElement} from '../lib/utils.js'; + export class PureTemplate extends React.Component { shouldComponentUpdate(nextProps) { return !isEqual(this.props.data, nextProps.data) || this.props.templateKey !== nextProps.templateKey; @@ -31,8 +31,8 @@ export class PureTemplate extends React.Component { return null; } - if (React.isValidElement(content)) { - return
{content}
; + if (isReactElement(content)) { + throw new Error('Support for templates as React elements has been removed, please use react-instantsearch'); } return
; diff --git a/src/components/__tests__/Template-test.js b/src/components/__tests__/Template-test.js index 6067c90bd7..9ddd4a4ec8 100644 --- a/src/components/__tests__/Template-test.js +++ b/src/components/__tests__/Template-test.js @@ -28,15 +28,14 @@ describe('Template', () => { expect(tree).toMatchSnapshot(); }); - it('supports templates as functions returning a React element', () => { + it('throws an error when templates as functions returning a React element', () => { const props = getProps({ - templates: {test: templateData =>

it also works with {templateData.type}

}, + templates: {test: templateData =>

it doesnt works with {templateData.type}

}, data: {type: 'functions'}, }); - const tree = renderer.create( + expect(() => renderer.create( - ).toJSON(); - expect(tree).toMatchSnapshot(); + )).toThrow(); }); it('can configure compilation options', () => { diff --git a/src/components/__tests__/__snapshots__/Template-test.js.snap b/src/components/__tests__/__snapshots__/Template-test.js.snap index 3520b70481..cdc28bdd76 100644 --- a/src/components/__tests__/__snapshots__/Template-test.js.snap +++ b/src/components/__tests__/__snapshots__/Template-test.js.snap @@ -82,15 +82,6 @@ exports[`Template without helpers can configure compilation options 1`] = ` /> `; -exports[`Template without helpers supports templates as functions returning a React element 1`] = ` -
-

- it also works with - functions -

-
-`; - exports[`Template without helpers supports templates as functions returning a string 1`] = `