question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

document `getSSRProps` for directives

See original GitHub issue

I believe the documentation is missing something or there is a bug about getSSRProps: https://v3.nuxtjs.org/guide/directory-structure/plugins/#vue-directives

When I copy the content and paste it into /plugins/focus.ts or /plugins/focus.client.ts (in a project without any directives just with pages) I get the same getSSRProps missing error as anyone above - but the besides the error, it seems to work on most mounted elements.

(To check, the .focus() changed to .style.color = 'green' did its job)

_Originally posted by @BananaAcid in https://github.com/nuxt/framework/issues/3154#issuecomment-1213340079_

Issue Analytics

  • State:open
  • Created a year ago
  • Reactions:2
  • Comments:10 (2 by maintainers)

github_iconTop GitHub Comments

1reaction
chris-vissercommented, Oct 24, 2022

Oh wauw. Just realized I posted my finding on my Passionate People account. I will repost this issue on the Vue repo. Thanks!

1reaction
Lyokoluxcommented, Aug 31, 2022

Turning it into a composable made it works:

import { Directive } from "vue"

type UseVOutsideFocusOnlyReturnType = {
  vOutsideFocusOnly: Directive
}
export const useVOutsideFocusOnly = (): UseVOutsideFocusOnlyReturnType => ({
 // recommend to use the same name in the whole app with a property
  vOutsideFocusOnly: {
    mounted(el: HTMLElement) {
      const { focused } = useFocusWithin(el)
      watch(focused, focused => {
        el.tabIndex = focused ? -1 : 0
      })
    },
    getSSRProps(binding, vnode) {
      // you can provide SSR-specific props here
      return {}
    }
  }
})

and in a <script> tag inside a vue component:

const { vOutsideFocusOnly } = useVOutsideFocusOnly()

and in the template:

<NuxtLink :to="myBeautifulLink" v-outside-focus-only>...</NuxtLink>

It solves my problem in Vue 3 with <script setup>. I don’t know how to solve it for Vue 2.7 though.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Vue SSR Directives - Quasar Framework
Declaring a Vue directive (or directly importing it) in a .vue SFC file is ... Vue directives to also specify a getSSRProps() method...
Read more >
Server-Side Rendering (SSR) - Vue.js
Unlike a fully static SPA that can be deployed on any static file server, ... add to the rendered element), you can use...
Read more >
Document directive - MDN Web Docs Glossary: Definitions of ...
CSP document directives are used in a Content-Security-Policy header and govern the properties of a document or worker environment to which ...
Read more >
How to use FunctionDirective in Vue3? - Stack Overflow
There 2 ways to declare a Vue directive - using an object syntax, where you declare all the hooks that your directive is...
Read more >
Directives Help — DOE Directives, Guidance, and Delegations
Enter dates to limit your search to a specific time period. Select whether you want to search for documents with a contractor requirements...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found