Vue No SSR

1.1.1 · renamed · verified Sun Apr 19

Vue No SSR was a component designed for Vue.js applications utilizing Server-Side Rendering (SSR) to wrap components that should only be rendered on the client side. Its primary function was to prevent hydration mismatches and allow browser-specific code or libraries to function correctly without causing errors during the SSR build process. The package's last version under this name was 1.1.1, released in early 2019. It was succeeded by `vue-client-only` in its 2.0.0 release, which is actively maintained. This component provided a simple API, allowing for fallback content (placeholders) to be displayed during SSR until the client-side component was mounted. It solved a common problem in isomorphic Vue applications where certain elements or third-party libraries are not compatible with Node.js environments.

Common errors

Warnings

Install

Imports

Quickstart

This example demonstrates how to use the `<no-ssr>` component to wrap `MyClientOnlyComponent`, which simulates a browser-dependent component. It shows both the `placeholder` prop and a `v-slot:placeholder` for fallback content while the main component awaits client-side hydration.

<template>
  <div id="app">
    <h1>My SSR-enabled Website</h1>
    <no-ssr placeholder="Loading client-only content...">
      <!-- This component might use browser-specific APIs or be incompatible with Node.js -->
      <MyClientOnlyComponent />
      <template v-slot:placeholder>
        <p>This content is client-only: Loading...</p>
      </template>
    </no-ssr>
    <p>This content is always visible (SSR and client).</p>
  </div>
</template>

<script>
import Vue from 'vue';
import NoSSR from 'vue-no-ssr';

// A dummy component that would typically rely on client-side APIs
const MyClientOnlyComponent = Vue.component('MyClientOnlyComponent', {
  template: '<div>Hello from the client! (Window width: {{ windowWidth }})</div>',
  data() {
    return { windowWidth: 0 };
  },
  mounted() {
    if (typeof window !== 'undefined') {
      this.windowWidth = window.innerWidth;
      window.addEventListener('resize', this.updateWidth);
    }
  },
  beforeDestroy() {
    if (typeof window !== 'undefined') {
      window.removeEventListener('resize', this.updateWidth);
    }
  },
  methods: {
    updateWidth() {
      this.windowWidth = window.innerWidth;
    }
  }
});

export default {
  name: 'App',
  components: {
    'no-ssr': NoSSR,
    MyClientOnlyComponent
  }
};
</script>

<style>
body { font-family: sans-serif; }
</style>

view raw JSON →