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

feat(vue-renderer): support prepend/append body tags during ssr for all allowed tag types #6134

Merged
merged 12 commits into from
Aug 19, 2019

Conversation

pimlie
Copy link

@pimlie pimlie commented Jul 26, 2019

This is a draft until #6121 is merged

Resolves: #6097

Types of changes

  • Bug fix (a non-breaking change which fixes an issue)
  • New feature (a non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to change)

Description

According to the html5 specs both meta, link, style, script as noscripts are allowed in the body. This was already support by VueMeta (thus Nuxt) on the client, but during SSR it wasnt yet.

Note, some tags are only allowed with certain attributes. Eg link must have a itemprop attribute, a link with a rel attribute is not allowed in the body. Its up to the user to use this features according to the spec.

Checklist:

  • My change requires a change to the documentation.
  • I have updated the documentation accordingly. (PR: #)
  • I have added tests to cover my changes (if not applicable, please state why)
  • All new and existing tests are passing.

@pimlie pimlie self-assigned this Jul 26, 2019
@codecov-io
Copy link

codecov-io commented Jul 27, 2019

Codecov Report

Merging #6134 into dev will decrease coverage by 0.02%.
The diff coverage is 92.85%.

Impacted file tree graph

@@            Coverage Diff             @@
##              dev    #6134      +/-   ##
==========================================
- Coverage   95.75%   95.72%   -0.03%     
==========================================
  Files          80       80              
  Lines        2660     2666       +6     
  Branches      684      687       +3     
==========================================
+ Hits         2547     2552       +5     
- Misses         97       98       +1     
  Partials       16       16
Flag Coverage Δ
#e2e 100% <ø> (ø) ⬆️
#fixtures 50.63% <7.14%> (-0.12%) ⬇️
#unit 92.42% <92.85%> (-0.03%) ⬇️
Impacted Files Coverage Δ
packages/vue-renderer/src/renderers/spa.js 87.69% <100%> (ø) ⬆️
packages/vue-renderer/src/renderers/ssr.js 93.65% <83.33%> (-1.09%) ⬇️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update f65c72d...220dd1f. Read the comment docs.

@pimlie pimlie marked this pull request as ready for review July 27, 2019 09:11
@pimlie pimlie requested a review from a team July 27, 2019 09:11
@pimlie
Copy link
Author

pimlie commented Jul 27, 2019

@clarkdo @pi0 Do you have any idea why the SPARenderer is being loaded on mode: 'ssr' ?

The basic.test fails at the moment due to my latest commit. The basic fixture is not a SPA build but the SPARendered is still being initiailzed. Because the SPARenderer is initialized before the SSR/ModernRenderer, VueMeta is loaded on the server but with the wrong config. Subsequent loads of VueMeta within the SSR App are ofc ignored because VueMeta is already loaded.

@clarkdo
Copy link
Member

clarkdo commented Jul 27, 2019

It makes switch SPA and SSR at runtime possible.

About the error does vue-meta store mode for different logic?

If so I think the mode should be passed in vue-meta initializing instead of module loading and can be changed at runtime since mode can be changed as well.

@pimlie
Copy link
Author

pimlie commented Jul 27, 2019

Yes, it uses the plugin options throughout its lifetime.

I have reverted the last commit as that wont ever work probably until v3. I either need to add support to VueMeta to make it possible to override options on calling vm.$meta.inject or Nuxt should do a search and replace in the SPA renderer. Both are not ideal ofc but probably the first is a bit cleaner.

Or maybe you have other/better suggestions?

@clarkdo
Copy link
Member

clarkdo commented Jul 27, 2019

I think you can check the mode config when passing ssrAppId and only do it when the value is spa, is that ok?

@pimlie
Copy link
Author

pimlie commented Jul 27, 2019

That would only be a partial fix I believe. Eg if somebody would switch during runtime from SSR to SPA then their SPA pages would still be generated with the wrong app id.

-- edit --
Maybe we should re-visit this issue so VueMeta supports rendering without Vue. Then we dont have to do that dirty trick in the SPARendered anymore either to get the metaInfo stuff (ping @manniL)

@clarkdo
Copy link
Member

clarkdo commented Jul 27, 2019

@pimlie I think swiching at runtime will re-run vue.use(VueMeata)

@pimlie
Copy link
Author

pimlie commented Jul 28, 2019

I have added support to VueMeta for directly generating tags from a metaInfo object. This means this PR is depending on #6153 for VueMeta v2.2

Creating the tags renderer (the object containing all the meta.text() stuff) is now at least two times faster for SPA mode. Before it took ~8-12ms, now it takes ~4-5ms

@Atinux
Copy link
Member

Atinux commented Jul 29, 2019

Before it took ~8-12ms, now it takes ~4-5ms

🔥

packages/vue-renderer/src/renderers/spa.js Show resolved Hide resolved
packages/vue-renderer/src/renderers/spa.js Outdated Show resolved Hide resolved
packages/vue-renderer/src/renderers/ssr.js Outdated Show resolved Hide resolved
@pi0 pi0 merged commit df424e5 into nuxt:dev Aug 19, 2019
@pi0 pi0 mentioned this pull request Aug 19, 2019
pi0 pushed a commit that referenced this pull request Aug 20, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Appending scripts and styles to the body not work on initial page load
7 participants