Vue3 - Suspense not displaying backup content

I have a parent component and a child component set up as follows:

.
├── Index.vue (Parent)
└── _GetShipment.vue (Child)

Within Index.vue, I am using Office.js's getAsync method to retrieve the content of an email body:

<script>
import Shipment from './_GetShipment.vue';
import { ref, defineComponent } from 'vue';


export default defineComponent({
    setup() {
        const shipments = ref([]);

        Office.context.mailbox.item.body.getAsync(
            "text",
            function (result) {
                if (result.status === Office.AsyncResultStatus.Succeeded) {
                    let matches = result.value.match(/S\w{3}\d{8,9}/ig);
                    if(matches){
                        shipments.value = matches;
                    }
                }
            }
        );

        return {
            shipments,
        }
    },
    components: {
        Shipment,
    },
})
</script>

<template>
     <div>
         <div v-if="shipments.length === 1">
             <Shipment :id="shipments[0]" />
         </div>
     </div>
</template>

The code snippet above checks the email body content for a specific regular expression match. If a match is found, it is added to the array shipments.

Currently, when only one match is found, it will be displayed in the child component named _GetShipment:

<script>
import { ref, Suspense } from 'vue';
import route from '../../../../vendor/tightenco/ziggy/src/js';

export default {
    props: ['id'],
    async setup(props) {
        const shipment = ref();
        await fetch(route('getShipment', {id : props.id}))
            .then(response => response.json())
            .then(data => shipment.value = data);
        return { shipment };

    }
};
</script>
<template>
      <div>
         Viewing shipment {{ id }}: <br />
         <Suspense>
             <template #fallback>
                 Loading...
             </template>
             <pre>{{ shipment }}</pre>
         </Suspense>
      </div>
</template>

The process of fetching the email body content and retrieving details using fetch() is functioning properly.

However, the loading fallback specified in the Suspense component is not triggering as expected. Instead, the page remains blank until the fetch operation is completed.

Why is the #fallback section not rendering?

Answer №1

It seems like you may be misusing the <Suspense> component by placing it within the same component that contains an async setup. The correct placement for the <Suspense> is in a parent component (any component between the root and the one with async setup).

If your component is rendering without errors, it suggests that there is already a <Suspense> in a higher-level ancestor component. To resolve this issue, consider removing the <Suspense> from your async setup component or relocating it to a surrounding wrapper that handles fallback rendering.

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

Implementing a NestJs application on a microcomputer like a Raspberry Pi or equivalent device

I'm facing a challenge in trying to find a solution for what seems like a simple task. I am aware that using the Nest CLI, I can utilize the command "nest build" to generate a dist folder containing the production files of my project. However, when I ...

What encoding does Algolia utilize to determine the size of a JSON entry - ASCII or UTF-8?

The FAQ document from Algolia states that the maximum size of an entry should be a minified JSON size of 10KB. However, it does not specify whether the JSON string should be ASCII or UTF-8 encoded, which makes it challenging to accurately calculate the siz ...

Error: Unrecognized HTML, CSS, or JavaScript code detected in template

I'm currently utilizing the "Custom HTML Tag" option in GTM with my code below, but encountering an error when attempting to publish: Invalid HTML, CSS, or JavaScript found in template. It seems that GTM may not support or recognize certain tag attri ...

Verify if the textbox is empty

Is there a way to verify that the input field with type "text" is not empty before moving to the next page? <input TYPE="text" name="textbox2" align="center"> ........ function HomeButton() { <!--if both textbox1 and textbox2 values are not ...

Child component not displaying React props (although I can identify them in debug mode)

Currently, I am working on a React project that does not involve Redux. However, I am encountering some difficulties in passing the state from the parent component to the child component. Despite watching numerous tutorials and extensively using the Chrome ...

When I run the "npm start" command, the console does not show any changes, leading me to believe that the code is not being updated in real-time. This behavior seems to be specific

When I run the command "npm start", I am not seeing any changes in the console. It seems like the code is not being updated on the fly. { "scripts": { "format": "prettier --write app", "start": "http-server" }, "dependencies": { "http-server": "^14.1.0" } ...

Adding a file attachment and preview feature within a text area: a step-by-step guide

I have been working on a chat box that includes emojis and a file attachment button. While the emojis are functioning correctly, I am experiencing difficulty with the file attachment preview not showing in the text area. Are there any suggestions or plugin ...

Place the simulation nodes in designated locations

Is there a proper way to position nodes at specific coordinates using simulation force in D3.js? I am trying to place nodes at specific positions with forceX/Y simulation in D3.js. My understanding is that setting the strength to 0 should result in no for ...

Hey there Angular enthusiasts! Facing a dilemma with scaffolding. Need help deciding which option is the best

I'm a newcomer to Angular and currently working on setting up an Angular project. I ran yo angular and after completing some initial steps, I reached a point where it presented me with the following question: ? Overwrite package.json? (ynaxdH) y) ...

The product has been taken out of the cart, yet it has not been reinserted into the cart

The product disappears from the cart after clicking on Add to Cart, but it doesn't reappear when clicked again. //function for adding only one item to cart document.getElementById('btn1').onclick = function() { addItemToCart() }; fun ...

Trouble encountered with bootstrap toggling when multiple identical inputs are used

Problem with Bootstrap toggle not working on multiple identical inputs unless the first input is pressed. Even then, not all inputs are checked/unchecked. I've created a small example I want to ensure that when one input is toggled, all others have ...

Having trouble with cross-origin requests while testing locally?

While trying to break down the tutorial found at https://tympanus.net/codrops/2019/03/26/exploding-3d-objects-with-three-js/ and downloading the source code, I've encountered some issues. The explanations provided are not detailed enough. When I run t ...

insert information into a fixed-size array using JavaScript

I am attempting to use array.push within a for loop in my TypeScript code: var rows = [ { id: '1', category: 'Snow', value: 'Jon', cheapSource: '35', cheapPrice: '35', amazonSource ...

Determine if every object in the array contains a specific key value pair

I am dealing with the following JSON data: { records:{ data:{ current:{ records:{ '2years':[{a:1, b:2, flag:true}, {a:2, b:4}, ...

How can you merge one object with two different mongoose models?

Consider the scenario where I have two mongoose models set up: User Model Business Favorite Model Currently, I'm successfully retrieving the combined result if a user has any favorite businesses. However, I suspect that my current implementation mi ...

Press the button in the parent component, retrieve information from the child component, and utilize it in a method (Vue 3)

I am currently using Vue3 in combination with Bootstrap 5. MY ISSUE: I am trying to click a button in my parent.vue. Upon clicking, I want to retrieve the data from my child.vue and access it within the method in my parent.vue. However, the data always r ...

Tips for loading Google fonts quickly using Font Face Observer

Upon reading an enlightening article on the optimal methods for serving web fonts, I was eager to employ the innovative javascript library known as Font Face Observer to asynchronously load Google fonts on my website. The documentation states that "fonts ...

Utilizing JavaScript to conceal div elements within a ul container

How can I hide specific div tags inside a ul tag using JavaScript? All div tags are currently getting hidden when I use the id of the ul tag. However, I need only the first div tag to be shown and the rest to be hidden. Here is the HTML code: <ul clas ...

Tips for having <script> update onchange instead of just onload

Is there a way to update the output of the <table id="mortgagetable"> each time a user changes the input values in the form? Currently, it only updates on load. Additionally, the content of the <div id="years" style="display:inline-block;">25 ...

Efficient - Managing numerous database connections

I am currently working on a project using node.js and I have created a login form where users need to select the database they want to connect to. However, I am uncertain about how to establish a connection with the selected database. Is there a way for m ...