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

Composition breaks when used with SSR #79

Closed
Maronato opened this issue May 4, 2020 · 1 comment
Closed

Composition breaks when used with SSR #79

Maronato opened this issue May 4, 2020 · 1 comment
Assignees
Labels
Priority: Medium Issues that will be worked on soon™ Type: Bug Something isn't working

Comments

@Maronato
Copy link
Owner

Maronato commented May 4, 2020

Versions

  • 1.6

Describe the bug

The plugin may be used by applications running with SSR. This causes everything to break.

vue-toastification/composition/index.js must be changed so it:

  • Does not use ES6 imports and exports
  • Replaces useToast and provideToast with dummy functions that do nothing on the server

Expected behavior

When using composition functions with frameworks like Nuxt, Vue toastification should not break the application.

Steps to reproduce

Use Nuxt with SSR and add the line

import { provideToast } from "vue-toastification/composition";

Fix suggestion

Possible fix:

const { inject, provide } = require("@vue/composition-api");

const toastSymbol = Symbol("Vue Toastification");

/** @type {ReturnType<typeof createToastInterface>} */
const injectDefault = {};


let createToastInterface = (options) => {
  console.warn("[Vue Toastification] This plugin does not support SSR!")
  return {}
}

if (typeof window !== 'undefined') {
  const toastification = require("vue-toastification");
  createToastInterface = toastification.createToastInterface
}

// Generate provider and consumer
const provideToast = options =>
  provide(toastSymbol, createToastInterface(options));
const useToast = () => inject(toastSymbol, injectDefault);

module.exports = { provideToast, useToast };
@Maronato Maronato added Type: Bug Something isn't working Priority: Medium Issues that will be worked on soon™ Status: Available labels May 4, 2020
@Maronato Maronato self-assigned this May 4, 2020
@Maronato Maronato closed this as completed May 5, 2020
@lock
Copy link

lock bot commented May 20, 2020

This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.

@lock lock bot locked and limited conversation to collaborators May 20, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Priority: Medium Issues that will be worked on soon™ Type: Bug Something isn't working
Projects
None yet
Development

No branches or pull requests

1 participant