Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

html template function returns "undefined" with empty string #6075

Open
1 task done
thumbtech opened this issue Feb 24, 2024 · 2 comments
Open
1 task done

html template function returns "undefined" with empty string #6075

thumbtech opened this issue Feb 24, 2024 · 2 comments

Comments

@thumbtech
Copy link

馃悰 Current behavior

Somewhere between algoliasearch@4.20.0 and 4.22.1, the html function used in a template changed such that html`` (empty string in html function) returns string undefined to template.

馃攳 Steps to reproduce

return html`` in a template

Live reproduction

na

馃挱 Expected behavior

Should be equivalent to return '' instead of return 'undefined'

Package version

instantsearch.js@4.65.0

Operating system

na

Browser

na

Code of Conduct

  • I agree to follow this project's Code of Conduct
@thumbtech thumbtech added the triage Issues to be categorized by the team label Feb 24, 2024
@Haroenv
Copy link
Contributor

Haroenv commented Feb 26, 2024

For which component is this, I just did a quick test for hits and can't reproduce:

test('renders empty template using `html`', async () => {
  const container = document.createElement('div');
  const searchClient = createMockedSearchClient();

  const search = instantsearch({ indexName: 'indexName', searchClient });

  search.addWidgets([
    hits({
      container,
      templates: {
        item(_, { html }) {
          return html``;
        },
      },
    }),
  ]);

  search.start();

  await wait(0);

  expect(container).toMatchInlineSnapshot(`
    <div>
      <div
        class="ais-Hits"
      >
        <ol
          class="ais-Hits-list"
        >
          <li
            class="ais-Hits-item"
          />
          <li
            class="ais-Hits-item"
          />
        </ol>
      </div>
    </div>
  `);
});

If there's anything happening that's causing it, I think it may be around here in the code, where undefined somehow gets casted as a string? If there's a clear repro, I wonder if the content === null check should be just !content as that shouldn't render in any case.

@Haroenv Haroenv added Library: InstantSearch.js Issues in instantsearch.js Scope: Templating Type: Bug Resolution: Needs More Information and removed triage Issues to be categorized by the team labels Feb 26, 2024
@thumbtech
Copy link
Author

It was in my template.empty, e.g.,

hits({
  // ...
  templates: {
    empty(results, { html }) {
      return html``;
    },
  },
});

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants