Unverified Commit 80998a05 authored by Jan Potoms's avatar Jan Potoms Committed by GitHub

Don't use assetprefix on getServerSideProps and getStaticProps (#15634)

Strictly use `basePath` and not `assetPrefix` on `getStaticProps` and `getServerSideProps`

Fixes https://github.com/vercel/next.js/issues/15563
parent 1a0cdbea
......@@ -6,6 +6,7 @@ import { searchParamsToUrlQuery } from './../next-server/lib/router/utils/search
import { parseRelativeUrl } from './../next-server/lib/router/utils/parse-relative-url'
import escapePathDelimiters from '../next-server/lib/router/utils/escape-path-delimiters'
import getAssetPathFromRoute from './../next-server/lib/router/utils/get-asset-path-from-route'
import { addBasePath } from '../next-server/lib/router/router'
function hasRel(rel, link) {
try {
......@@ -127,9 +128,9 @@ export default class PageLoader {
const getHrefForSlug = (/** @type string */ path) => {
const dataRoute = getAssetPathFromRoute(path, '.json')
return `${this.assetPrefix}/_next/data/${this.buildId}${dataRoute}${
ssg ? '' : search || ''
}`
return addBasePath(
`/_next/data/${this.buildId}${dataRoute}${ssg ? '' : search}`
)
}
let isDynamic = isDynamicRoute(route),
......
......@@ -66,12 +66,12 @@ describe('absolute assetPrefix with path prefix', () => {
afterAll(() => cdn.close())
afterAll(() => nextConfig.restore())
it('should be able to fetch static data from a CDN', async () => {
it('should not fetch static data from a CDN', async () => {
const browser = await webdriver(appPort, '/')
await browser.waitForElementByCss('#about-link').click()
const prop = await browser.waitForElementByCss('#prop').text()
expect(prop).toBe('hello')
expect(cdnAccessLog).toContain(`/_next/data/${buildId}/about.json`)
expect(cdnAccessLog).not.toContain(`/_next/data/${buildId}/about.json`)
})
it('should fetch from cache correctly', async () => {
......@@ -88,7 +88,7 @@ describe('absolute assetPrefix with path prefix', () => {
cdnAccessLog.filter(
(path) => path === `/_next/data/${buildId}/about.json`
)
).toHaveLength(1)
).toHaveLength(0)
})
it('should work with getStaticPaths prerendered', async () => {
......@@ -96,7 +96,7 @@ describe('absolute assetPrefix with path prefix', () => {
await browser.waitForElementByCss('#gsp-prerender-link').click()
const prop = await browser.waitForElementByCss('#prop').text()
expect(prop).toBe('prerendered')
expect(cdnAccessLog).toContain(
expect(cdnAccessLog).not.toContain(
`/_next/data/${buildId}/gsp-fallback/prerendered.json`
)
})
......@@ -106,7 +106,7 @@ describe('absolute assetPrefix with path prefix', () => {
await browser.waitForElementByCss('#gsp-fallback-link').click()
const prop = await browser.waitForElementByCss('#prop').text()
expect(prop).toBe('fallback')
expect(cdnAccessLog).toContain(
expect(cdnAccessLog).not.toContain(
`/_next/data/${buildId}/gsp-fallback/fallback.json`
)
})
......@@ -116,6 +116,8 @@ describe('absolute assetPrefix with path prefix', () => {
await browser.waitForElementByCss('#gssp-link').click()
const prop = await browser.waitForElementByCss('#prop').text()
expect(prop).toBe('foo')
expect(cdnAccessLog).toContain(`/_next/data/${buildId}/gssp.json?prop=foo`)
expect(cdnAccessLog).not.toContain(
`/_next/data/${buildId}/gssp.json?prop=foo`
)
})
})
......@@ -80,7 +80,7 @@ describe('Production response size', () => {
)
// These numbers are without gzip compression!
const delta = responseSizesBytes - 274 * 1024
const delta = responseSizesBytes - 275 * 1024
expect(delta).toBeLessThanOrEqual(1024) // don't increase size more than 1kb
expect(delta).toBeGreaterThanOrEqual(-1024) // don't decrease size more than 1kb without updating target
})
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment