Why is Vite's hot reloading feature displaying unpredictable outcomes?

I have a unique setup consisting of Vite, Typescript, and Vue 3 SPA utilizing "script setup". This app is equipped with Urql to query data from a GraphQL endpoint.

An interesting occurrence happens where the query results are only displayed after the component has been hotloaded.

Here's how events unfold:

  1. Upon loading the app at http://localhost:4000, everything seems fine except that the data from the query returns as 'undefined'. The Loading indicator briefly appears, but result.data.value remains undefined.
  2. Reloading the page doesn't make any difference - the Loading indicator flashes momentarily, yet result.data.value stays undefined.
  3. Saving the component (Ctrl + s) in VS Code yields the same outcome as steps 1 and 2.
  4. When making a minor change like modifying a comment within the component code and saving it, the component undergoes hotloading as indicated by the console. Surprisingly, the Loading indicator disappears, and this time, result.data.value contains the expected two elements which are then displayed on the page.
  5. Another reload of the page brings us back to square one - the page loads but the query results remain undefined.

You can take a look at the code on GitHub: here

/src/components/TodoPrivateList.vue is where the data is fetched (line 29). At line 71, it utilizes a child component TodoItem.vue to render each Todo item.

Through Vue DevTools observation, I notice that the data is consistently retrieved, yet the Todos fail to render. Only triggering a hot reload of TodoPrivateList.vue (by updating a comment, for instance) results in properly rendering the Todos.

It seems to align with @wittgenstein's suggestion that this could be a Reactivity issue, although the solution remains uncertain at this point.

I appreciate any assistance you can offer on this matter.

Answer №1

The problem was unrelated to Vite.

It turned out that the issue occurred due to not properly awaiting the response from the graphql query.

To resolve this, I utilized the "Suspense" option in the parent component (an experimental feature in Vue 3) and included 'await' in the query. The updated code has been successfully pushed to GitHub.

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Tips for updating the front end with the status of a lengthy playwright test

In the node backend, I have defined a route for test progress using SSE (https://developer.mozilla.org/en-US/docs/Web/API/Server-sent_events/Using_server-sent_events). The URL initialization is happening on the frontend. Below is the code snippet from th ...

Looking to tweak the date format in a Vue.js template?

I received the following format: 2019-01-08T11:11:00.000Z However, I need it to be in this format: 2019-01-08 Does anyone know how to achieve this date formatting without using the moment package? ...

Mapping JSON data from an array with multiple properties

Here is a JSON object that I have: obj = { "api": "1.0.0", "info": { "title": "Events", "version": "v1", "description": "Set of events" }, "topics": { "cust.created.v1": { "subscribe": { ...

Attempting to successfully pass a URL in Vue and append an API string to it

I want to input an image URL in a text field, then display that URL in an image tag but also modify the original URL by adding an API string at the end. Check out the JavaScript code below: Vue.component('imagesinstagram', { props: [&apos ...

What is the process of creating and verifying a Laravel random and temporary password?

I am seeking assistance in implementing a function that can generate an unpredictable password and subsequently verify if the user is utilizing the previously generated password. Your help and guidance are highly valued. Thank you sincerely! ...

Using Vue-router and Typescript with beforeEnter guard - utilizing validated data techniques

As I utilize Vue along with vue-router and typescript, a common scenario arises where a single page is dedicated to displaying a Photo component. A route includes a beforeEnter guard that checks my store to verify the existence of the requested photo. ...

Attempting to link the input field with a data value on a Vue page

I'm currently facing an issue with my table and binding the input element to the "project_settings" object. The goal is to have the values inside the project_settings object change based on whether the checkbox is checked or not. However, every time I ...

Why is it necessary to include a dollar sign before interpolation in Angular?

While diving into a tutorial, I stumbled upon a piece of code that piqued my curiosity. I grasped the concept that appending a dollar sign as a suffix indicates observability, but I wonder why the dollar sign was also prefixed to this.log(`updated hero i ...

A step-by-step guide on sending a fetch request to TinyURL

I have been attempting to send a post request using fetch to tinyURL in order to shorten a URL that is generated on my website. The following code shows how I am currently writing the script, however, it seems like it's not returning the shortened URL ...

Modifying the values of Highcharts-Vue chart options does not result in any changes once they have been

I recently started incorporating Highcharts into my Vue project using the highcharts-vue library. A) Initially, in pure JavaScript, the following code snippet functions as expected: let b = 5; let data = { a: b } console.log('data', data.a) ...

Vuejs symbols are not recognizable by Sublime Text 3

When I work with Sublime Text, I usually access function names by using the "@" symbol list. However, when working with a project created from vue-templates, I noticed that all the function names and data attributes in .vue files do not show up in this lis ...

What is the best way to implement a comprehensive switch case in Typescript using string enums that are referencing other string enums?

I am faced with a challenge where I have a subset of values from one enum that I need to switch case across in TypeScript. Here's an example to illustrate my dilemma: const enum Fruit { APPLE = 'Apple', BANANA = 'Banana', ...

What is the best way to structure files within the css and js folders after running the build command in Vue-cli?

Vue-cli typically generates files in the following structure: - dist -- demo.html -- style.css -- file.commom.js -- file.commom.js.map -- file.umd.js -- file.umd.js.map -- file.umd.min.js -- file.umd.min.js.map However, I prefer to organize them this way: ...

The spread operator seems to be malfunctioning whenever I incorporate tailwindcss into my code

Hi there! I hope you're doing well! I've come across a strange issue in Tailwindcss. When I close the scope of a component and try to use props like ...rest, the className doesn't function as expected. Here's an example: import { Butto ...

Invalid for the purpose of storage

Encountering the following error message: The dollar ($) prefixed field '$size' in 'analytics.visits.amounts..$size' is not valid for storage. return Manager.updateMany({}, { $push: { & ...

Issue with bootstrap modal new line character not functioning properly

Is there a correct way to insert a new line for content in a modal? I have this simple string: 'Please check the Apple and/or \nOrange Folder checkbox to start program.' I placed the '\n' newline character before "Orange," e ...

Automatically convert TypeScript packages from another workspace in Turborepo with transpilation

I have set up a Turborepo-based monorepo with my primary TypeScript application named @myscope/tsapp. This application utilizes another TypeScript package within the same repository called @myscope/tspackage. For reference, you can view the example reposit ...

What causes different errors to occur in TypeScript even when the codes look alike?

type Convert<T> = { [P in keyof T]: T[P] extends string ? number : T[P] } function customTest<T, R extends Convert<T>>(target: T): R { return target as any } interface Foo { x: number y: (_: any) => void } const foo: Foo = c ...

Router-view failing to display component

I am currently working on setting up basic routing in Vue. I have identified three file listings that seem to be causing issues. When I include <router-view> in app.vue, the foo component appears in the browser. However, when I follow the instruction ...

How to smoothly scroll a child div when the parent div is set as position sticky in vue JS

My landing page requires a unique feature: when a user enters a specific <section>, that section should become fixed while the elements inside the corresponding <div> start scrolling. Once the inner div has finished scrolling, the parent <se ...