When a Vue component collapses on itself, it prevents the next component from rendering

Within my primary component, known as App.vue, I have structured the template code like so:

<template>
<div class="app-wrapper">
    <Header></Header>
    <Panel></Panel>
    <Showcase/>
    <Modal/>
    <Footer/>
</div>
</template>

This is simply a mock-up of an application I am working on, hence the lack of nesting and meaningful content within each part.

Each of these Vue Components follow a similar structure in their respective .vue files:

<template>
  <div class="panel-wrapper">Panel</div>
</template>

<script lang="ts">
import Vue from "vue";
export default Vue.extend({
  name: "Panel"
});
</script>


<style lang="scss">
.panel-wrapper {
  background: orange;
  font-size: 1.75rem;
}
</style>

The same format applies to Header, Showcase, Modal, and Footer.

Strangely, when implementing the above code, only the Header, Panel, and Showcase components are visible. If I modify <Showcase/> by adding closing tags as

<Showcase></Showcase>
, the Modal also becomes visible.

Isn't it expected for components to render regardless of whether they self-terminate their JSX?

I am new to Vue and have independently set up the project with TypeScript and Parcel. I am unsure if this setup influences the rendering issue.

Answer №1

An ongoing problem has been identified with the Parcel bundler. The issue lies in Parcel's use of posthtml as an HTML parser, which struggles with custom self-closing HTML tags.

To address this temporarily, it is necessary to instruct the bundler to explicitly acknowledge self-closing custom elements. You can achieve this by adding the following configuration to your package.json:

"posthtml": {
    "recognizeSelfClosing": true
}

Current updates on this issue can be found in these threads: issue-1 and issue-2.

Answer №2

The official vue style guide recommends self-closing components in single-file components, string templates, and JSX, but not in DOM templates.

Components with no content should be self-closing to adhere to Vue's guidelines. You can read more about this here.

Custom elements cannot be self-closed in HTML, only the official "void" elements are allowed to be. This strategy is only feasible when Vue's template compiler can preprocess the template before rendering the DOM, ensuring compliance with HTML specifications.

Answer №3

When working with Vue templates, it's important to remember that they must be valid HTML. The use of self-closing tags in the XHTML syntax is now considered outdated. To ensure your Vue templates adhere to best practices, you can refer to the style guide provided in the Vue documentation Official Style Guide Vuejs

For further insights on valid tags in HTML, you may find this discussion on stackoverflow helpful: Are (non-void) self-closing tags valid in HTML5?

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 modifying the status of a single component within a v-for loop without impacting other components

I am encountering an issue with my childComponent that is dynamically rendered using v-for within the parentComponent. The Parent component contains logic to fetch data from the database and display it on the screen. The fetch request query is dependent on ...

Implementing computed properties: A guide to incorporating type setting

I currently have two separate interfaces defined for Person and Dog. interface Person { name: string; weight: number; } interface Dog { name: string; mass: number } const specificAttribute = isDog ? 'mass' : 'weight'; ...

enhancing the types of parameters in a function declaration without relying on generics

My goal is to improve developer experience (DX) by expanding the types for parameters in a function signature. I want the tooltip when hovering over the following function to provide more detailed information: type Props = { a: number; }; const func = ( ...

Finding the precise directory of a local JSON file for an Axios GET request in Vue.js

In my Vue project, I have prepared some dummy data for future development. The test data is stored in a `json` file, and my Vue project follows the typical structure created with Vue-Cli: My_project build config data service_general_in ...

Vue.js renders components after the job is completed

Currently, I am dealing with a component that requires me to initiate a request using socket.io: <template> <h1>Please do not display until the socket responds</h1> </template> <script> export default { befor ...

Exploring the integration of multiple HTTP requests in Angular with the power of RxJS

Is there a way to make multiple HTTP calls simultaneously in an Angular service and then combine the responses into one object using RxJS? import { Injectable } from '@angular/core'; import { HttpClient } from '@angular/common/http'; im ...

Vue Router failing to render template

I am working on implementing a Vue Router in my Vue application. However, when I click the link, it simply reloads the page instead of displaying the Dashboard template. Any suggestions on how to resolve this issue? Here is the relevant code snippet from ...

Utilize the keep-alive feature to cache a single route component dynamically

I am working on conditionally setting the keep-alive feature for some of my route components. I want to be able to clear the cached routes and set new ones when necessary. The code I have written below is functional, but I am facing an issue with clearing ...

When attempting to select dates from the picker options, the array is found to be devoid of any entries

My challenge lies in working with an array of dates retrieved from the server to determine which dates should be disabled on the datepicker. getStaffAvailability(){ let x = this; this.$http.get(this.weeklyAvailabilityUrl + "GetAv ...

Transforming class attributes in Typescript

I am facing a situation where I need to alter the type of a variable that stores an object based on certain conditions. Here is the variable in question: class MyClass { public referrers: SelectItemGroup[]; } The issue arises when I only need to add a ...

Setting up NGINX to efficiently serve JPG images to a Vue.js frontend within a Docker container

I am facing a challenge with replacing npm's http-server with NGINX as a static file server when transitioning from a local setup to a dockerized environment. My current setup involves an app built using Flask + Gunicorn + Vue.js + THREE.js. The text ...

The function Event.target.value is coming back as null

I've been working on creating a timer window, and I've set up a separate component for it. However, I'm facing an issue with passing the time from the main component to the child component. The problem lies in the fact that the state of the ...

Tips for avoiding the default rendering of Nuxt 3 layout?

After reviewing the Nuxt 3 documentation and finding it lacking in explanation, I turned to the Nuxt 2 docs. According to them, the default layout should be replaced by a specific layout specified within the name property of the <nuxt-layout> compone ...

Is there a way to utilize const assertions to retrieve the explicit types from objects nested at various levels?

In reference to this question, the previous structure had a depth of 2: const grandkids = { Karen: { Ava: ['Alice', 'Amelia'], Emma: ['Sarah'], }, Mary: { Sophia: ['Grace'], }, } as const; To ext ...

What is the most effective way to retrieve cursors from individual entities in a Google Cloud Datastore query?

I am currently working on integrating Google Cloud Datastore into my NodeJS application. One issue I have encountered is that when making a query, only the end cursor is returned by default, rather than the cursor for each entity in the response. For insta ...

Having trouble getting the waveform to load in IOS Safari when using WavesurferJS in a VueJS application, even though the audio is playing fine

In my VueJS application, I've been facing a challenge with WavesurferJS on IOS Safari for the past week. The issue is that the wavesurfer component cannot fully decode the audio or load the waveform, resulting in just a thin straight line being displa ...

The inline $Emit function is not generating the correct random number when using Math.random()

I've been diving into the concept of $emit event in Vue and came across this tutorial: . I tried implementing something similar using Vue2.js, but every time I click the button, it gives me a rounded number instead of a random number like in the guide ...

What is the best way to activate a modal in the parent component when a button is clicked in the child component?

Currently I have the following setup: panelHeader.vue (which is a child component) index.vue (the parent component where my main list view is) panelHeader.vue <template> <v-row> <div class="panelHeader"> ...

Using parameters to create unions in TypeScript

Is there a standard method to parametrically define a union? I'm searching for a way to generically define something like: type U<K> = T<K1> | T<K2> | ... | T<Kn> // Where K === (K1 | ... | Kn) Note: I'm encountering a s ...

Firebase: The Firebase application under the name '[DEFAULT]' is already present (app/duplicate-app)

My Nuxt/Vue.js application requires me to export various Firestore-related elements instead of just firebase.firestore(). Despite this, I am encountering an error stating Firebase App named '[DEFAULT]' already exists (app/duplicate-app) with the ...