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

Fetch() is called twice when using is-Directive / Dynamic Component #198

Open
jony1993 opened this issue May 24, 2021 · 1 comment
Open

Comments

@jony1993
Copy link

Describe the bug
If a component has a fetch() and is included via a dynamic component <component :is="..."/> , then the fetch() is called twice (on ssr AND client). When registering the component globally (e.g. via a plugin), its working and fetch() is only called once.

To Reproduce
Sandbox: https://codesandbox.io/s/blue-bush-5lyew

  1. Open https://5lyew.sse.codesandbox.io/childDirect --> See that fetch is only called on ssr
  2. Open https://5lyew.sse.codesandbox.io/childViaComponent --> See that fetch is called on ssr and client

Expected behavior
Fetch should be only called once when SSR is activated

Additional context
Background: We are trying to load a list of components from our CMS (Storyblok), and want to show these components via the dynamic component.

@marcohofmann
Copy link

marcohofmann commented May 24, 2021

Hey @jony1993 ;-)
Thanks for reporting! Today i tried to use <component /> with a manual component import and a disabled auto-import. It worked as expected without calling fetch() two times:

// page/index.vue
<template>
  <div>
    <div v-for="(widget, index) in widgets" :key="index">
      <component :is="widget.__type" />
    </div>
  </div>
</template>

<script>
export default {
  components: {
    fetch: () => import('@/components/fetch.vue')
  },
  data () {
    return {
      widgets: [
        { __type: 'fetch' }
      ]
    }
  }
}
</script>
// components/fetch.vue
<template>
  <div>fetch</div>
</template>

<script>
export default {
  async fetch() {
    await console.log('fetch')
  }
}
</script>

But with an enabled auto-import fetch() is called two-times (SSR & client). Also navigating from page to page on the client.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants