Skip to content

Content Template Functions Invoked on Server Render Only #426

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

Closed
johndugan opened this issue Jul 30, 2019 · 6 comments
Closed

Content Template Functions Invoked on Server Render Only #426

johndugan opened this issue Jul 30, 2019 · 6 comments
Labels

Comments

@johndugan
Copy link

I am using a Content Template for my og:title content, as the example in the docs is. However, unlike the titleTemplate, which is invoked on both server and client SPA renders, Content Templates are only invoked on server renders. In my universal Nuxt application, following hydration, the content template function is not invoked when switching pages. This appears to be a bug.

@pimlie
Copy link
Collaborator

pimlie commented Jul 31, 2019

Please add a reproduction for this

@johndugan
Copy link
Author

Here is the content template defined in my nuxt.config.js file.

{
    hid: 'og:title',
    property: 'og:title',
    content: '',
    template: (content) =>
        `St. Thomas The Apostle Parish Festival ${content}`.trim()
}

Here is the relevant code in my events.vue page component.

export default {
    name: 'EventsPage',
    head: function() {
        return {
            title: this.seoTitle,
            meta: [
                {
                    hid: 'description',
                    name: 'description',
                    content: this.seoDescription
                },
                {
                    hid: 'og:title',
                    property: 'og:title',
                    content: this.seoTitle
                },
                {
                    hid: 'og:description',
                    property: 'og:description',
                    content: this.seoDescription
                }
            ]
        };
    },
    components: {
        EventsNav: EventsNav,
        EventCard: EventCard
    },
    data: function() {
        return {
            seoTitle: 'Events',
            seoDescription:
                "From the Turkey Dinner to the Live Music, learn more about all of the events at this year's parish festival!",
            events: events
        };
    }
};

Below are steps to reproduce the issue of the the content template function not being called on client side page changes.

  1. Visit https://www.parishfestival.org/
  2. Click the "Events" link.
  3. The og:title value on the events page is Events (ignores the content template).
  4. Refresh the page events page to get a server render. The value is St. Thomas The Apostle Parish Festival Events (as expected).

@pimlie
Copy link
Collaborator

pimlie commented Jul 31, 2019

Thanks for the repro. Which vue-meta version are you using?

In v2 I cant reproduce your exact problem. But it seems that in v2 the content template is being execute more than once, so the text part of the content template is listed more then once (eg Page Title - My Site - My Site - My Site)

@johndugan
Copy link
Author

Nuxt version 2.8.1 whose vue-meta dependency is ^1.6.0 in node_modules/@nuxt/vue-app/package.json. However, it seems they've updated vue-meta for a nuxt version that has not been released? ...see nuxt/nuxt#6153

@TheAlexLichter
Copy link
Member

@johndugan Yes, a major update will land in Nuxt in the next minor version (v2.9)

@pimlie
Copy link
Collaborator

pimlie commented Aug 4, 2019

The content template issue I found is fixed in v2.2.1, if you still experience an issue make sure you have this version installed instead of Nuxt's default v1.

@pimlie pimlie closed this as completed Aug 4, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants