Why Quasar PWA + SSR server-rendered source code not work for production build generated code?

I create a from scratch new project based on the latest @quasar/cli.

Unfortunately the PWA + SSR usage mentionned here: https://quasar.dev/quasar-cli-vite/developing-ssr/ssr-with-pwa/ only work in Development mode and NOT WORK in Production.

As soon as you create a Production build, it’s not work anymore.

To resume, inside quasar.config.js (or quasar.config.ts)

For Only SSR case

// ...
ssr: {
    // ...
    pwa: false
    // ...
}
// ...

quasar dev -m ssr produce a source server-side rendering.
quasar build -m ssr then cd dist/ssr then node index.js produce a source server-side rendering.

but

For PWA + SSR case

// ...
ssr: {
    // ...
    pwa: true
    // ...
}
// ...

quasar dev -m ssr produce a source server-side rendering
quasar build -m ssr then cd dist/ssr then node index.js NOT GENERATE server-side code.

Question: what configuration I missed and I should add, at build time or at running node time, to made server-side rendering work?


Below all the instruction to reproduce the bug:

  • On Windows 11

  • With nvm 1.1.12

  • With node 20.12.0

  • With npm 10.5.0

  • Create a quasar directory, and move inside

  • Run npm i -g @quasar/cli

  • Run npm init quasar
    — Install [email protected]
    — Choose App with Quasar CLI, let’s go!
    — Project folder: quasar-project
    — Pick Quasar version: Quasar v2(Vue 3 | latest and geartest)
    — Choose TypeScript
    — Chose Quasar App CLI with Vite 2 (stable | v1)
    — Package name: quasar-project
    — Project product name: Quasar App
    — Project description: A Quasar Project
    — Author: SkeptRaiser
    — Pick a Vue component style: Composition API
    — Pick your CSS preprocessor: Sass with SCSS syntax
    — Chose Linting / State Management (Pinia) / axios / vue-i18n
    — Pick an ESLint preset: Prettier
    — Install project dependencies? Yes, use npm

  • Move inside directory quasar-project

  • Add line "dev-ssr": "quasar dev -m ssr", after "dev" to "$scripts" property under package.json from directory quasar-project

  • Run npm run dev-ssr

  • Reach view-source:http://localhost:9100/ and see the source look like following

<!DOCTYPE html>
<html lang=en-US dir=ltr>
  <head>
    <script type="module" src="/@vite/client"></script>
    <script type="module">
import { inject } from "/@vite-plugin-checker-runtime";
inject({
  overlayConfig: {},
  base: "/",
});
</script>
<script>window.__INITIAL_STATE__={};document.currentScript.remove()</script>
    <title>Quasar App</title>

    ...
  </head>
  <body class="desktop no-touch body--light" data-server-rendered>
    <div id="q-app"><div class="q-layout q-layout--standard" style="min-height:0px;" tabindex="-1">...</div></div><script type="module" src="/.quasar/client-entry.js"></script>
  </body>
</html>

with a rendered body that is CORRECT EXPECTED BEHAVIOR.

  • Add line "build-ssr": "quasar build -m ssr" after "build" to "$scripts" property under package.json from directory quasar-project
  • Run npm run build-ssr
  • Move inside directory dist/ssr
  • Run node index.js
  • Reach view-source:http://localhost:3000/ and see the source look like following
<!DOCTYPE html><html lang=en-US dir=ltr><head><script>window.__INITIAL_STATE__={};document.currentScript.remove()</script> <title>Quasar App</title>...</head><body class="desktop no-touch body--light" data-server-rendered> <div id="q-app"><div class="q-layout q-layout--standard" style="min-height:0px;" tabindex="-1">...</div></div></body></html>

with a rendered body that is CORRECT EXPECTED BEHAVIOR.

  • Move outside directory and back to quasar-project directory
  • Change line 144 pwa: false, to pwa: true, in the config ssr: property from file quasar.config.js
  • Run npm run dev-ssr
  • Reach view-source:http://localhost:9100/ and see the source look like following
<!DOCTYPE html>
<html lang=en-US dir=ltr>
  <head>
    <script type="module" src="/@vite/client"></script>
    <script type="module">
import { inject } from "/@vite-plugin-checker-runtime";
inject({
  overlayConfig: {},
  base: "/",
});
</script>
<script>window.__INITIAL_STATE__={};document.currentScript.remove()</script>
    <title>Quasar App</title>

    ...
  </head>
  <body class="desktop no-touch body--light" data-server-rendered>
    <div id="q-app"><div class="q-layout q-layout--standard" style="min-height:0px;" tabindex="-1">...</div></div><script type="module" src="/.quasar/client-entry.js"></script>
  </body>
</html>

with a rendered body that is CORRECT EXPECTED BEHAVIOR.

  • Run npm run build-ssr
  • Move inside directory dist/ssr
  • Run node index.js
  • Reach view-source:http://localhost:3000/ and see the source look like following
<!DOCTYPE html><html lang=en-US dir=ltr><head><script>window.__INITIAL_STATE__={};document.currentScript.remove()</script> <title>Quasar App</title>...</head><body class="desktop no-touch body--light" data-server-rendered> <div id="q-app"><div class="q-layout q-layout--standard" style="min-height:0px;" tabindex="-1">...</div></div></body></html>

with a rendered body that is CORRECT EXPECTED BEHAVIOR.

  • Move outside directory and back to quasar-project directory
  • Add line "dev-pwa": "quasar dev -m pwa", after "dev" to "$scripts" property under package.json from directory quasar-project
  • Run npm run dev-pwa
  • Reach view-source:http://localhost:9200/ and see the source look like following
<!DOCTYPE html>
<html>
  <head>
    <script type="module" src="/@vite/client"></script>
    <script type="module">
import { inject } from "/@vite-plugin-checker-runtime";
inject({
  overlayConfig: {},
  base: "/",
});
</script>

    <title>Quasar App</title>

    ...
  </head>
  <body>
    <div id="q-app"></div><script type="module" src="/.quasar/client-entry.js"></script>
  </body>
</html>

with a NO rendered body that is CORRECT EXPECTED BEHAVIOR.

    • Add line /src-pwa after /src-cordova property under .eslintignore from directory quasar-project
  • Run npm run dev-ssr
  • Reach view-source:http://localhost:9150/ and see the source look like following
<!DOCTYPE html>
<html lang=en-US dir=ltr>
  <head>
    <script type="module" src="/@vite/client"></script>
    <script type="module">
import { inject } from "/@vite-plugin-checker-runtime";
inject({
  overlayConfig: {},
  base: "/",
});
</script>
<script>window.__INITIAL_STATE__={};document.currentScript.remove()</script>
    <title>Quasar App</title>

    ...
  </head>
  <body class="desktop no-touch body--light" data-server-rendered>
    <div id="q-app"><div class="q-layout q-layout--standard" style="min-height:0px;" tabindex="-1">...</div></div><script type="module" src="/.quasar/client-entry.js"></script>
  </body>
</html>

with a rendered body that is CORRECT EXPECTED BEHAVIOR.

  • Run npm run build-ssr
  • Move inside directory dist/ssr
  • Run node index.js
  • Reach view-source:http://localhost:3000/ and see the source look like following
<!DOCTYPE html><html><head><title>Quasar App</title>...</head><body><div id=q-app></div></body></html>

with a NO rendered body that is NOT EXPECTED BEHAVIOR.

Edited answer:

It seems to be linked to the service-worker mechanism itself. If your service-worker not run

enter image description here

then you will see the SSR render code from server under view-source:

But if the service-worker run

enter image description here

The view-source: feature will so you an empty ssr response from server. This behavior not depend on dev or build command but depend on the activation or not of service-worker.

Original answer:

It seems it’s a bug with Chrome view-source: feature.

If I use a wget http://localhost:3000/ then I read the index.html file downloaded cat index.html I effectively see the correct rendered code inside the downloaded file.

From Firefox, the view-source: feature show the correct rendered code if you use the reload button front of URL search bar (but if you just reach it, the render is not present and I correctly not know why).

Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa Dịch vụ tổ chức sự kiện 5 sao Thông tin về chúng tôi Dịch vụ sinh nhật bé trai Dịch vụ sinh nhật bé gái Sự kiện trọn gói Các tiết mục giải trí Dịch vụ bổ trợ Tiệc cưới sang trọng Dịch vụ khai trương Tư vấn tổ chức sự kiện Hình ảnh sự kiện Cập nhật tin tức Liên hệ ngay Thuê chú hề chuyên nghiệp Tiệc tất niên cho công ty Trang trí tiệc cuối năm Tiệc tất niên độc đáo Sinh nhật bé Hải Đăng Sinh nhật đáng yêu bé Khánh Vân Sinh nhật sang trọng Bích Ngân Tiệc sinh nhật bé Thanh Trang Dịch vụ ông già Noel Xiếc thú vui nhộn Biểu diễn xiếc quay đĩa Dịch vụ tổ chức tiệc uy tín Khám phá dịch vụ của chúng tôi Tiệc sinh nhật cho bé trai Trang trí tiệc cho bé gái Gói sự kiện chuyên nghiệp Chương trình giải trí hấp dẫn Dịch vụ hỗ trợ sự kiện Trang trí tiệc cưới đẹp Khởi đầu thành công với khai trương Chuyên gia tư vấn sự kiện Xem ảnh các sự kiện đẹp Tin mới về sự kiện Kết nối với đội ngũ chuyên gia Chú hề vui nhộn cho tiệc sinh nhật Ý tưởng tiệc cuối năm Tất niên độc đáo Trang trí tiệc hiện đại Tổ chức sinh nhật cho Hải Đăng Sinh nhật độc quyền Khánh Vân Phong cách tiệc Bích Ngân Trang trí tiệc bé Thanh Trang Thuê dịch vụ ông già Noel chuyên nghiệp Xem xiếc khỉ đặc sắc Xiếc quay đĩa thú vị
Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa
Thiết kế website Thiết kế website Thiết kế website Cách kháng tài khoản quảng cáo Mua bán Fanpage Facebook Dịch vụ SEO Tổ chức sinh nhật