question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

More generic SSR support

See original GitHub issue

Hi, thanks for this library! I’m maintaining a couple of packages for SSR with Vite and I’m interested in supporting vue-query. I see the SSR support is experimental so I would like to add some feat requests to make it easier to integrate with other tools.

It would be great if we could create and provide a Query Client outside of a component, just like any other Vue library that is installed when creating the app:

const queryClient = new QueryClient({ ... })

app.use(queryClient) // This would use queryClient.install method to run `app.provide(..., queryClient)`

Everything else could probably work in the same way, but this gives us the ability to export this created client to pass it to any SSR tool we need (for callinghydrate or dehydrate), which are normally outside of component scopes. Thanks!

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Comments:9 (9 by maintainers)

github_iconTop GitHub Comments

2reactions
DamianOsipiukcommented, Aug 21, 2021
0reactions
wobsorianocommented, Aug 21, 2021

@DamianOsipiuk So, as far as I understand, an example using vite-ssr or vitedge would look like this:

// main.js
import App from './App.vue'
import viteSSR from 'vite-ssr/vue'
import { QueryClient } from 'vue-query'
import { hydrate, dehydrate } from 'vue-query/ssr'

export default viteSSR(
  App,
  {
    routes: [],
    transformState(state, defaultTransformer) {
      if (import.meta.env.SSR) {
        state.vueQuery = dehydrate(state.vueQuery)
      }

      return defaultTransformer(state)
    },
  },
  ({ app, initialState }) => {
    const client = new QueryClient()
    if (!import.meta.env.SSR) hydrate(client, initialState.vueQuery)
    initialState.vueQuery = client
  }
)
<script>
// App.vue
import { useContext } from 'vite-ssr'
import { useQueryProvider } from 'vue-query'

export default {
  setup() {
    const { initialState } = useContext()
    useQueryProvider(initialState.vueQuery)
  },
}
</script>

However, this crashes with error Could not resolve "@nuxtjs/composition-api" since the vue-query/ssr module is importing Nuxt-related stuff. I’ve tried importing from vue-query/ssr/hydration but that’s not exposed, unfortunately. Can the Nuxt stuff be separated from the agnostic hydration?

Thanks!

Same problem here https://github.com/DamianOsipiuk/vue-query/discussions/66

Read more comments on GitHub >

github_iconTop Results From Across the Web

SSRs (Special Service Requests) - Travelport
A Special Service Request (SSR) can be made in a PNR on behalf of one traveler, several travelers, or all travelers for specific...
Read more >
Special Services Request (SSR) codes and airline-specific ...
List of all Special Service Request (SSR) codes, and where to find airline-specific ancillary codes.. Amadeus.
Read more >
Special Service Request (SSR) Codes - Wheelchair Travel
When a traveler requests special assistance, the airline codes that into their ticket record using a special service request code, or SSR.
Read more >
NextJS / React SSR: 21 Universal Data Fetching Patterns ...
This approach makes the code within the component a lot more readable as it only handles the "happy path". As we're already supporting...
Read more >
SSR (Special Service Request) Codes - FlyerTalk Forums
Important note: When you add text to further define a generic SSR code such as OTHS, or SPML, use plain text. You can...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found