Skip to content
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

Prefetch Issue For SSR + PWA App On Production #17406

Open
kevinmnm opened this issue Jul 31, 2024 · 0 comments
Open

Prefetch Issue For SSR + PWA App On Production #17406

kevinmnm opened this issue Jul 31, 2024 · 0 comments
Labels
bug/1-repro-available A reproduction is available and needs to be confirmed. flavour/quasar-cli-vite kind/bug 🐞 mode/pwa mode/ssr Qv2 🔝 Quasar v2 issues

Comments

@kevinmnm
Copy link

kevinmnm commented Jul 31, 2024

What happened?

I'm trying to build SSR + PWA app without having to modify service worker. The issue only occurs on production environment (with valid TLS cert).

The issue is preFetch triggers in client side after user's initial visit to the website, leaving dummyStore.data empty. Also, api-.defaults.baseURL doesn't persist its state from server side to client side.

App.vue:

<script setup lang="ts">
import { onBeforeMount, onMounted } from 'vue';
import { api } from 'src/boot/axios';
import { useDummyStore } from 'src/stores/dummy';

defineOptions({
   name: 'App',
   async preFetch({ store }) {
      //>> This log should never show on browser console but it does after initial load (refresh the page) <<//
      console.log('preFetch');
      const dummyDataFetchURL = 'https://dummyjson.com/products';
      try {
         const dummyStore = useDummyStore(store);
         const result = await api.get(dummyDataFetchURL);
         dummyStore.data = result.data;

         //>> Setting default headers for axios which doesn't persist in client side (such as in `onBeforeMount()`) <<//
         api.defaults.baseURL = 'https://dummyjson.com';

         return;
      } catch (error) {
         throw error;
      }
   },
});

const dummyStore = useDummyStore();

onBeforeMount(() => {
   console.warn('onBeforeMount', {
      //>> undefined after initial visit (.e.g 2nd visit to app after refresh) <<//
      data: dummyStore.data,
      //>> undefined, even though it should be set in preFetch. <<//
      baseURL: api.defaults.baseURL,
   });
});

onMounted(() => {
   console.warn('onMounted', {
      //>> undefined after initial visit (.e.g 2nd visit to app after refresh) <<//
      data: dummyStore.data,
      //>> undefined, even though it should be set in preFetch. <<//
      baseURL: api.defaults.baseURL,
   });
});
</script>

Check the full setup for details but you'll have to somehow apply TLS or deploy to production to actually see the issue. I'm guessing this is due to PWA service worker caching assets but I'd rather not custom create service worker.

What did you expect to happen?

I expected preFetch to trigger every time on SSR + PWA build as it's a core feature of SSR.

Reproduction URL

https://stackblitz.com/edit/quasarframework-wwjavn?file=package.json,quasar.config.js

How to reproduce?

  1. Host reproduction code or similar in production environment with valid TLS.
  2. The preFetch will trigger in server when visiting the website for the first time.
  3. Refresh the page.
  4. The preFetch will now trigger on client side instead.

Flavour

Quasar CLI with Vite (@quasar/cli | @quasar/app-vite)

Areas

SSR Mode, PWA Mode

Platforms/Browsers

Firefox, Chrome, Safari, Microsoft Edge

Quasar info output

Operating System - Windows_NT(10.0.22621) - win32/x64
NodeJs - 20.13.1

Global packages
  NPM - 10.5.2
  yarn - Not installed
  @quasar/cli - 2.4.1
  @quasar/icongenie - Not installed
  cordova - Not installed

Important local packages
  quasar - 2.16.6 -- Build high-performance VueJS user interfaces (SPA, PWA, SSR, Mobile and Desktop) in record time
  @quasar/app-vite - 1.9.3 -- Quasar Framework App CLI with Vite
  @quasar/extras - 1.16.12 -- Quasar Framework fonts, icons and animations
  eslint-plugin-quasar - Not installed
  vue - 3.4.35 -- The progressive JavaScript framework for building modern web UI.
  vue-router - 4.4.0
  pinia - 2.2.0 -- Intuitive, type safe and flexible Store for Vue      
  vuex - Not installed
  vite - 2.9.18 -- Native-ESM powered web dev build tool
  eslint - 8.57.0 -- An AST-based pattern checker for JavaScript.       
  electron - Not installed
  electron-packager - Not installed 
  @electron/packager - Not installed
  electron-builder - Not installed  
  register-service-worker - 1.7.2 -- Script for registering service worker, with hooks
  @capacitor/core - Not installed   
  @capacitor/cli - Not installed    
  @capacitor/android - Not installed
  @capacitor/ios - Not installed    

Quasar App Extensions
  *None installed*

Networking
  Host - kevinmnm
  Ethernet - 192.168.1.153
  vEthernet (WSL (Hyper-V firewall)) - 172.23.144.1

Relevant log output

No response

Additional context

No response

@kevinmnm kevinmnm added kind/bug 🐞 Qv2 🔝 Quasar v2 issues labels Jul 31, 2024
@github-actions github-actions bot added bug/1-repro-available A reproduction is available and needs to be confirmed. flavour/quasar-cli-vite mode/pwa mode/ssr labels Jul 31, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug/1-repro-available A reproduction is available and needs to be confirmed. flavour/quasar-cli-vite kind/bug 🐞 mode/pwa mode/ssr Qv2 🔝 Quasar v2 issues
Projects
None yet
Development

No branches or pull requests

1 participant