algolia / vue-instantsearch

👀 Algolia components for building search UIs with Vue.js
https://www.algolia.com/doc/guides/building-search-ui/what-is-instantsearch/vue
MIT License
854 stars 157 forks source link

Is SSR support for Nuxt 3 planned ? #1125

Closed robinsimonklein closed 1 year ago

robinsimonklein commented 2 years ago

SSR for Nuxt 3 ⚡️

What is your use case for such a feature?

As Nuxt 3 is currently in Release Candidate version and its stable version is planned for "midsummer 2022" (see here), is the support of SSR with <AisInstantSearchSsr> planned ?

From what I have been able to test so far, using <AisInstantSearch> for client-side rendering seems to work well with Nuxt 3. However, when implementing SSR as shown in the Algolia documentation, using <AisInstantSearchSsr> does not work. I guess that createRootMixin and/or some other parts will have to be adapted to the new Nuxt 3 prerequisites.

What is your proposal

I'm not so familiar with InstantSearch or Nuxt low-level concepts but if there is any way I can help, I would :)

What is the version you are using?

v4.3.3

Haroenv commented 2 years ago

Thanks for opening this issue, I wasn't aware Nuxt 3 was this close to ready. Server-side rendering works in Vue 3, so should also work in theory in Nuxt 3. The relevant code is here: https://github.com/algolia/vue-instantsearch/blob/master/src/util/createServerRootMixin.js and https://github.com/algolia/vue-instantsearch/blob/master/src/components/InstantSearchSsr.js#L15 (although not much in that second file).

If you already have a test setup with nuxt 3 + Vue InstantSearch that isn't working, it would save time implementing support if you could share that!

robinsimonklein commented 2 years ago

Hi @Haroenv , thanks for the quick answer.

As I was working on a private project that I couldn't share, I took a moment to reproduce a project that is close to reality on CodeSandbox. You can find it here : https://codesandbox.io/s/nuxt-3-instantsearch-test-9c7oj5?file=/app.vue.

So here is the current state:

Hope this can help you!

Haroenv commented 2 years ago

I tried as well to get it working without the layout and got closer by marking the CJS packages for vite in nuxt config:

import { defineNuxtConfig } from 'nuxt'

// https://v3.nuxtjs.org/api/configuration/nuxt.config
export default defineNuxtConfig({
    build: {
        transpile: ['vue-instantsearch', 'instantsearch.js/es'],
    },
    vite: {
        optimizeDeps: {
            exclude: ['algoliasearch-helper', 'hogan.js']
        }
    }
})
bootsmann1995 commented 1 year ago

@Haroenv Is there any live example on Nuxt 3 with ais-instant-search-ssr ?

Haroenv commented 1 year ago

No, I haven't yet made an example. If you do, please share in this thread :)