Skip to content

fix(vue-compat): make renderCompat tolerate React-style JSX#7029

Draft
aymeric-giraudet wants to merge 1 commit into
chore/port-widget-skill-gaps-modefrom
chore/port-widget-vue-compat
Draft

fix(vue-compat): make renderCompat tolerate React-style JSX#7029
aymeric-giraudet wants to merge 1 commit into
chore/port-widget-skill-gaps-modefrom
chore/port-widget-vue-compat

Conversation

@aymeric-giraudet
Copy link
Copy Markdown
Member

Stacked on top of #7020 (port-widget skill improvements).

Summary

Foundational compat fixes that the upcoming Vue recommendation/chat ports need. No widget changes.

  • The augmented JSX `h` in `renderCompat` now tolerates `null` props from shared `` JSX in both Vue 2 and Vue 3. The destructure used to throw `Cannot destructure property 'className' of null`.
  • Vue 2 `util/vue-compat/index-vue2.js`:
    • Exports a `Fragment` shim (returns its children) so the default `EmptyComponent` / `DefaultItem` from `instantsearch-ui-components/recommend-shared` don't crash. Vue 3 re-exports the native `Fragment` from `vue`.
    • Translates React-style `onClick` / `onAuxClick` props from JSX into Vue 2's `on: { click, auxclick }` event API so shared UI components dispatch events instead of rendering them as literal HTML attributes (`onclick="() => {…}"`).
  • Vue 3 `util/vue-compat/index-vue3.js` now forwards `children` as a prop for function tags. Without this, components like `Button` that read `{children}` from props rendered as empty `` because Vue 3 puts children in `slots.default`.

Test plan

  • `npx jest packages/vue-instantsearch --no-coverage` — Vue 2 and Vue 3 (via `scripts/prepare-vue3.js`) suites green.
  • No widget behavior changes; existing tests still pass on both engines.

Next in the stack: common test infrastructure refactor.

`instantsearch-ui-components` ships React-style functional components
that the recommendation widgets render via the augmented JSX `h`. Three
gaps in the existing compat layer made shared factories crash or render
empty markup in Vue:

- The augmented `h` destructured `propsWithClassName` directly, so any
  JSX child rendered with `null` props (e.g. `<Fragment>x</Fragment>`)
  threw `Cannot destructure property 'className' of null`. Vue 2 and
  Vue 3 now both guard the destructure against `null`.
- Vue 2 had no native `Fragment` and the augmented `h` didn't translate
  React-style `onClick`/`onAuxClick` props into Vue 2's `on: { click,
  auxclick }` event API, so default `EmptyComponent`s crashed and event
  handlers fell through as literal HTML attributes (`onclick="() => {…}"`).
  Adds a Vue 2 `Fragment` shim and remaps React-style handlers.
- In Vue 3, children for functional components go to `slots.default`
  rather than `props.children`, so shared components like `Button` that
  read `{children}` rendered as empty `<button><!----></button>`.
  Mirrors the Vue 2 behavior by forwarding `children` as a prop for
  function tags.

No widget changes; this only makes the compat layer ready for the
shared UI factories used by the upcoming Vue recommendation/chat ports.
@codacy-production
Copy link
Copy Markdown

Up to standards ✅

🟢 Issues 0 issues

Results:
0 new issues

View in Codacy

🟢 Metrics 0 complexity · 0 duplication

Metric Results
Complexity 0
Duplication 0

View in Codacy

TIP This summary will be updated as you push new changes.

@pkg-pr-new
Copy link
Copy Markdown

pkg-pr-new Bot commented May 13, 2026

More templates

algoliasearch-helper

npm i https://pkg.pr.new/algolia/instantsearch/algoliasearch-helper@7029

instantsearch-ui-components

npm i https://pkg.pr.new/algolia/instantsearch/instantsearch-ui-components@7029

instantsearch.css

npm i https://pkg.pr.new/algolia/instantsearch/instantsearch.css@7029

instantsearch.js

npm i https://pkg.pr.new/algolia/instantsearch/instantsearch.js@7029

react-instantsearch

npm i https://pkg.pr.new/algolia/instantsearch/react-instantsearch@7029

react-instantsearch-core

npm i https://pkg.pr.new/algolia/instantsearch/react-instantsearch-core@7029

react-instantsearch-nextjs

npm i https://pkg.pr.new/algolia/instantsearch/react-instantsearch-nextjs@7029

react-instantsearch-router-nextjs

npm i https://pkg.pr.new/algolia/instantsearch/react-instantsearch-router-nextjs@7029

vue-instantsearch

npm i https://pkg.pr.new/algolia/instantsearch/vue-instantsearch@7029

commit: d4714e5

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant