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

fix: fix encoding issues with payload paths #8738

Merged
merged 10 commits into from
Feb 2, 2021
14 changes: 7 additions & 7 deletions packages/vue-renderer/src/renderers/ssr.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { format } from 'util'
import fs from 'fs-extra'
import consola from 'consola'
import { TARGETS, urlJoin } from '@nuxt/utils'
import { parsePath, withoutTrailingSlash } from 'ufo'
import { $URL, withoutTrailingSlash } from 'ufo'
import devalue from '@nuxt/devalue'
import { createBundleRenderer } from 'vue-server-renderer'
import BaseRenderer from './base'
Expand Down Expand Up @@ -180,7 +180,11 @@ export default class SSRRenderer extends BaseRenderer {
if (renderContext.staticAssetsBase) {
const preloadScripts = []
renderContext.staticAssets = []
const { staticAssetsBase, url, nuxt, staticAssets } = renderContext
const { staticAssetsBase, nuxt, staticAssets } = renderContext
let url = new $URL(renderContext.url).pathname
danielroe marked this conversation as resolved.
Show resolved Hide resolved
if (!this.options.router.trailingSlash) {
url = withoutTrailingSlash(url) || '/'
pi0 marked this conversation as resolved.
Show resolved Hide resolved
}
const { data, fetch, mutations, ...state } = nuxt

// Initial state
Expand Down Expand Up @@ -210,11 +214,7 @@ export default class SSRRenderer extends BaseRenderer {
// Page level payload.js (async loaded for CSR)
const payloadPath = urlJoin(url, 'payload.js')
const payloadUrl = urlJoin(staticAssetsBase, payloadPath)
let routePath = parsePath(url).pathname // remove query params
if (!this.options.router.trailingSlash) {
routePath = withoutTrailingSlash(routePath) || '/'
}
const payloadScript = `__NUXT_JSONP__("${routePath}", ${devalue({ data, fetch, mutations })});`
const payloadScript = `__NUXT_JSONP__("${url}", ${devalue({ data, fetch, mutations })});`
staticAssets.push({ path: payloadPath, src: payloadScript })
preloadScripts.push(payloadUrl)
// Add manifest preload
Expand Down