-
-
Notifications
You must be signed in to change notification settings - Fork 3.6k
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’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Quasar + Nuxt3 + SSR #11165
Comments
@piscis |
@JeRabix sorry have forgotten to make it public it should work now |
@rstoenescu Same issue, do we have any plans to support Nuxt3 ? thanks |
Looking at the type-definitions of the vite plugin I could find that a Source: Lines 24 to 31 in 3311a20
But I'm confused if that means that Quasar + Vite + SSR could eventually work with SSR / SSG frameworks like nuxt? |
I am having the same issue with quasar-app-vite and it is caused by defining quasar in noExternal, which bundles quasar.esm.prod.js which in turn is a browser build. |
Update: please see my comment here: #11165 (comment) |
I managed to get it working like this:
import { NuxtApp } from 'nuxt/dist/app/nuxt';
import {Quasar} from 'quasar';
import '@quasar/extras/roboto-font/roboto-font.css'
import '@quasar/extras/material-icons/material-icons.css'
import '@quasar/extras/fontawesome-v6/fontawesome-v6.css'
// Import Quasar css
import 'quasar/dist/quasar.css'
export default defineNuxtPlugin((nuxtApp: NuxtApp): unknown => {
nuxtApp.vueApp.use(Quasar, {})
return {
}
}) (remember to run
Even though I'm glad I finally can render Quasar in Nuxt 3, some questions came up: |
Quasar has its own SSR logic and functions which need to be handled appropriately. In contrast to most UI frameworks, Quasar has built in support for SSR and things are rendered differently depending on if its rendered on the server or the client: quasar/ui/src/plugins/Platform.js Lines 14 to 20 in ac8441d
Quasar only officially supports using @quasar/app-vite. It is possible to use Quasar SSR with Nuxt, but Nuxt will have to add support for Quasar. It definitely is possible, but not without some workarounds. If you want to use SSR with Quasar, use Quasar CLI. |
Providing SSR rendered Quasar components to Nuxt seems pretty straight forward (replace the platform variables with the correct If any experienced Nuxt user knows how to do this, it should be possible to have Quasar SSR support in Nuxt. |
Im new to Nuxt and to SSR. No idea. I just wanted to have Quasar as UI in Nuxt instead of Vuetify. |
Not with the latest and greatest Nuxt 3 and your latest components. , node 16.15.1 nuxt.conifg.ts => Should just be i**mport { defineNuxtConfig } from "nuxt";** And I get these errors. Something in the syntax must have changed for registering components. I am completely new with your product and would appreciate a little help. Thanks! [Vue warn]: Failed to resolve component: q-layout |
This solved my warning problems. It seems to be working with the original template with just two changes. Both of them are in the nuxt.config.ts. |
There is an update for Nuxt3 (now rc13) and Quasar 2 here: https://github.com/piscis/nuxt-quasar-boilerplate By using JSDOM as server plugin and mocking browser dependencies it is now possible to run a full SSR build. But for complicated layouts using q-layout there are still hydration errors probably caused by resize observer. |
@Jason What was funny about my message!? |
@angelhdzmultimedia, I found it funny because I had the exact same mindset. All the other emoticons didn't accurately describe on how I felt about your comment, so I choose the laughing one. |
Oooh. That makes sense. My apologies for being paranoid but I've received the laughing reaction before as a way of judging my answers so I'm always in full paranoia mode, also I suffer from generalized anxiety. So cool that other people faced the same wall I faced with Nuxt+ Quasar. Hope there's an official solution soon other than disabling SSR and making then app an SPA one. Also, I'm considering trying Quasar CLI + Vite and its SSR. Thank you for your time! Cheers. |
@angelhdzmultimedia I had similar issue and went with Quasar + Vite route. Copied most of Vite plugins from https://github.com/antfu/vitesse to make Quasar feel more like Nuxt (auto-imports of components, pages, layouts etc). Using it's SSR with tRPC v10 for backend. Pretty good DX, a bit slow to start due to bloat of plugins strapped. |
By using JSDOM to mock the DOM, we can use Quasar 2 with Nuxt 3. You can refer to this article for more details. import { JSDOM } from "jsdom";
const dom = new JSDOM(
"<!DOCTYPE html><head></head><body><h1>FAKE DOM</h1></body></html>",
{
url: "https://example.org/",
referrer: "https://example.com/",
contentType: "text/html",
includeNodeLocations: true,
storageQuota: 10000000,
}
);
const { XMLHttpRequest } = dom.window;
global.XMLHttpRequest = XMLHttpRequest;
// @ts-ignore
global.window = dom.window;
global.navigator = dom.window.navigator;
global.document = dom.window.document;
// @ts-ignore
global.FileList = dom.window.FileList;
global.File = dom.window.File;
global.getComputedStyle = dom.window.getComputedStyle;
export default defineNuxtPlugin((_nuxtApp): void => {}); |
Does not this approach disable Quasar CLI? |
Yup, same here. I went full Quasar with router/layouts/modules auto-import . But then I got back to Nuxt 3 to check if support for Quasar was added after Vuetify 3 was released. With Nuxt 3, we have the auto-imports already. No need to install bunch of packages. |
@NikolaStojicic , |
Got it working thanks. I followed the boilerplate carefully. Nuxt config is the same. fake-dom.server.ts is the same. |
Hello everybody, I did some more work on this topic and now it seems, that fully SSR support with quasar is possible. To get SSR to work I used the https://github.com/piscis/nuxt-quasar-boilerplate/blob/main/plugins/fake-dom.server.ts A boilerplate with the full source code can be found here: https://github.com/piscis/nuxt-quasar-boilerplate/ and the demo is here: https://github.com/piscis/nuxt-quasar-boilerplate |
Also please note what gets promoted here #11165 (comment) a old implementation with JSDOM. This is problematic when it comes to SSR and Quasar because some APIs quasar needs are not provided via JSDOM and lead to rehydration errors with q-layout / q-page when used with Nuxt3 + SSR |
@piscis What you've done is quite nice, do you think it's possible to go further and make it a nuxt module, just like element-plus? |
@xuzuodong yes that is possible I guess. The biggest problem with the current implementation is that you need to wire everything by hand in a plugin. If this is covered via a module, we would need some sort of component configuration. I already toke some inspiration from https://github.com/sfxcode/nuxt-primevue to see how they solve it for primevue |
Closing this as using our CLI(s) to develop SSR is the official way to go, at least for now. And this ticket is confusing some developers into thinking that Quasar does not supports SSR, which couldn't be more WRONG. Our Vite plugin supports SSR through its params (configures all the Everyone please feel free to still comment on this thread with your findings, but again, take into account that our Vite plugin has specific params for SSR. https://github.com/quasarframework/quasar/blob/dev/vite-plugin/index.d.ts#L32 |
Thank you! I have a question: That's the reason I've been working with Nuxt 3 lately instead of Quasar with Vite. |
Using Do keep in mind that there are hydration issues with some of the Quasar components at the moment. ( |
Will try it tonight, thanks! |
Tried it. It works great. Looked at the source code. Are you using jsdom or @happy-dom/global-registrator to avoid the "undefined property window" errors? Or did you found another way? |
Window errors are due to Instead of resolving imports to |
Hey @piscis, not intend to bother you. Just wanted you to noticed this solution and know your thoughts. Wishing you all health, peace, and success! Have fun! 😊🔥🤝☕ |
I will try this out for a new project I am currently working on, at a first glance (2h playing around) it seems to work fine.
I did not stumble upon this yet, though if it becomes to troublesome I am luckily in the position where I could also live without SSR. I am mostly using Quasar for the great components.
This is also our main motivation for Nuxt. We mostly use Quasar as a component library and Nuxt for the file based routing, (typed) API routes, but also some other neat modules (though some of those have yet to be ported to Nuxt 3). |
Is your feature request related to a problem? Please describe.
I would really like to integrate Quasar into Nuxt 3 with SSR mode enabled. I have a working prototype (
yarn dev
) that uses the Quasar Vite Plugin + Nuxt3.The repo is here: https://github.com/piscis/nuxt-quasar-boilerplate/tree/example/quasar-vite-nuxt3-working
How every as soon as I enable SSR in nuxt.config.ts and restart vite I get the following error when my components render on the server:
Looking at the server.mjs bundle I noticed helper referencing "window" for example:
Describe the solution you'd like
I would like to enable Nuxt3 SSR mode and use Quasar Components and beeing able to render Quasar Components on the server side.
Describe alternatives you've considered
nuxt-image
,nuxt-head
,nuxt-recatpcha
aso. Also all of the new features like deployment to Cloudflare worker aso. Are missing with quasar SSR.But that didn't help.
Additional context
I think supporting Nuxt 3 instead of shipping a custom build SSR integration could expose Quasar Framework even more in the VUE/Nuxt ecosystem. Probably the new Nuxt CLI
nuxi
could help to build a wrapper around nuxt so quasar cli could provide similar support like it does today with capacitor / cap cli.please note
yarn build
fails at the moment due to: nuxt/bridge#27The text was updated successfully, but these errors were encountered: