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 ...@@ -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 { parseRelativeUrl } from './../next-server/lib/router/utils/parse-relative-url'
import escapePathDelimiters from '../next-server/lib/router/utils/escape-path-delimiters' 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 getAssetPathFromRoute from './../next-server/lib/router/utils/get-asset-path-from-route'
import { addBasePath } from '../next-server/lib/router/router'
function hasRel(rel, link) { function hasRel(rel, link) {
try { try {
...@@ -127,9 +128,9 @@ export default class PageLoader { ...@@ -127,9 +128,9 @@ export default class PageLoader {
const getHrefForSlug = (/** @type string */ path) => { const getHrefForSlug = (/** @type string */ path) => {
const dataRoute = getAssetPathFromRoute(path, '.json') const dataRoute = getAssetPathFromRoute(path, '.json')
return `${this.assetPrefix}/_next/data/${this.buildId}${dataRoute}${ return addBasePath(
ssg ? '' : search || '' `/_next/data/${this.buildId}${dataRoute}${ssg ? '' : search}`
}` )
} }
let isDynamic = isDynamicRoute(route), let isDynamic = isDynamicRoute(route),
......
...@@ -66,12 +66,12 @@ describe('absolute assetPrefix with path prefix', () => { ...@@ -66,12 +66,12 @@ describe('absolute assetPrefix with path prefix', () => {
afterAll(() => cdn.close()) afterAll(() => cdn.close())
afterAll(() => nextConfig.restore()) 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, '/') const browser = await webdriver(appPort, '/')
await browser.waitForElementByCss('#about-link').click() await browser.waitForElementByCss('#about-link').click()
const prop = await browser.waitForElementByCss('#prop').text() const prop = await browser.waitForElementByCss('#prop').text()
expect(prop).toBe('hello') 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 () => { it('should fetch from cache correctly', async () => {
...@@ -88,7 +88,7 @@ describe('absolute assetPrefix with path prefix', () => { ...@@ -88,7 +88,7 @@ describe('absolute assetPrefix with path prefix', () => {
cdnAccessLog.filter( cdnAccessLog.filter(
(path) => path === `/_next/data/${buildId}/about.json` (path) => path === `/_next/data/${buildId}/about.json`
) )
).toHaveLength(1) ).toHaveLength(0)
}) })
it('should work with getStaticPaths prerendered', async () => { it('should work with getStaticPaths prerendered', async () => {
...@@ -96,7 +96,7 @@ describe('absolute assetPrefix with path prefix', () => { ...@@ -96,7 +96,7 @@ describe('absolute assetPrefix with path prefix', () => {
await browser.waitForElementByCss('#gsp-prerender-link').click() await browser.waitForElementByCss('#gsp-prerender-link').click()
const prop = await browser.waitForElementByCss('#prop').text() const prop = await browser.waitForElementByCss('#prop').text()
expect(prop).toBe('prerendered') expect(prop).toBe('prerendered')
expect(cdnAccessLog).toContain( expect(cdnAccessLog).not.toContain(
`/_next/data/${buildId}/gsp-fallback/prerendered.json` `/_next/data/${buildId}/gsp-fallback/prerendered.json`
) )
}) })
...@@ -106,7 +106,7 @@ describe('absolute assetPrefix with path prefix', () => { ...@@ -106,7 +106,7 @@ describe('absolute assetPrefix with path prefix', () => {
await browser.waitForElementByCss('#gsp-fallback-link').click() await browser.waitForElementByCss('#gsp-fallback-link').click()
const prop = await browser.waitForElementByCss('#prop').text() const prop = await browser.waitForElementByCss('#prop').text()
expect(prop).toBe('fallback') expect(prop).toBe('fallback')
expect(cdnAccessLog).toContain( expect(cdnAccessLog).not.toContain(
`/_next/data/${buildId}/gsp-fallback/fallback.json` `/_next/data/${buildId}/gsp-fallback/fallback.json`
) )
}) })
...@@ -116,6 +116,8 @@ describe('absolute assetPrefix with path prefix', () => { ...@@ -116,6 +116,8 @@ describe('absolute assetPrefix with path prefix', () => {
await browser.waitForElementByCss('#gssp-link').click() await browser.waitForElementByCss('#gssp-link').click()
const prop = await browser.waitForElementByCss('#prop').text() const prop = await browser.waitForElementByCss('#prop').text()
expect(prop).toBe('foo') 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', () => { ...@@ -80,7 +80,7 @@ describe('Production response size', () => {
) )
// These numbers are without gzip compression! // 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).toBeLessThanOrEqual(1024) // don't increase size more than 1kb
expect(delta).toBeGreaterThanOrEqual(-1024) // don't decrease size more than 1kb without updating target 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