-
-
Notifications
You must be signed in to change notification settings - Fork 2.5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix dynamic prerender conflict (#10298)
* Reproduce issues * Handle inconsistency between static, dynamic and rest routes * Add extra test cases * Add changeset * Revert unrelated changes * Update lockfile
- Loading branch information
Showing
17 changed files
with
322 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
--- | ||
"astro": patch | ||
--- | ||
|
||
Fix an incorrect conflict resolution between pages generated from static routes and rest parameters |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
import assert from 'node:assert/strict'; | ||
import { before, describe, it } from 'node:test'; | ||
import * as cheerio from 'cheerio'; | ||
import { loadFixture } from './test-utils.js'; | ||
|
||
describe('Dynamic route collision', () => { | ||
/** @type {import('./test-utils').Fixture} */ | ||
let fixture; | ||
|
||
before(async () => { | ||
fixture = await loadFixture({ | ||
root: './fixtures/dynamic-route-collision', | ||
}); | ||
|
||
await fixture.build().catch(console.log); | ||
}); | ||
|
||
it('Builds a static route when in conflict with a dynamic route', async () => { | ||
const html = await fixture.readFile('/about/index.html'); | ||
const $ = cheerio.load(html); | ||
assert.equal($('h1').text(), 'Static About'); | ||
}); | ||
|
||
it('Builds a static route when in conflict with a spread route', async () => { | ||
const html = await fixture.readFile('/who/index.html'); | ||
const $ = cheerio.load(html); | ||
assert.equal($('h1').text(), 'Static Who We Are'); | ||
}); | ||
|
||
it('Builds a static nested index when in conflict with a spread route', async () => { | ||
const html = await fixture.readFile('/tags/index.html'); | ||
const $ = cheerio.load(html); | ||
assert.equal($('h1').text(), 'Static Tags Index'); | ||
}); | ||
|
||
it('Builds a static root index when in conflict with a spread route', async () => { | ||
const html = await fixture.readFile('/index.html'); | ||
const $ = cheerio.load(html); | ||
assert.equal($('h1').text(), 'Static Index'); | ||
}); | ||
|
||
it('Builds a static index a nested when in conflict with a dynamic+spread route', async () => { | ||
const html = await fixture.readFile('/en/index.html'); | ||
const $ = cheerio.load(html); | ||
assert.equal($('h1').text(), 'Dynamic-only Localized Index'); | ||
}); | ||
|
||
it('Builds a dynamic route when in conflict with a spread route', async () => { | ||
const html = await fixture.readFile('/blog/index.html'); | ||
const $ = cheerio.load(html); | ||
assert.equal($('h1').text(), 'Dynamic Blog'); | ||
}); | ||
|
||
it('Builds the highest priority route out of two conflicting dynamic routes', async () => { | ||
const html = await fixture.readFile('/order/index.html'); | ||
const $ = cheerio.load(html); | ||
assert.equal($('h1').text(), 'Order from A'); | ||
}); | ||
}); |
8 changes: 8 additions & 0 deletions
8
packages/astro/test/fixtures/dynamic-route-collision/package.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
{ | ||
"name": "@test/dynamic-route-collision", | ||
"version": "0.0.0", | ||
"private": true, | ||
"dependencies": { | ||
"astro": "workspace:*" | ||
} | ||
} |
35 changes: 35 additions & 0 deletions
35
packages/astro/test/fixtures/dynamic-route-collision/src/pages/[...slug].astro
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
--- | ||
export async function getStaticPaths() { | ||
const pages = [ | ||
{ | ||
slug: undefined, | ||
title: 'Rest Index', | ||
}, | ||
{ | ||
slug: 'blog', | ||
title: 'Rest Blog', | ||
}, | ||
{ | ||
slug: 'who', | ||
title: 'Rest Who We Are', | ||
}, | ||
]; | ||
return pages.map(({ slug, title }) => { | ||
return { | ||
params: { slug }, | ||
props: { title }, | ||
}; | ||
}); | ||
} | ||
const { title } = Astro.props; | ||
--- | ||
|
||
<html> | ||
<head> | ||
<title>{title}</title> | ||
</head> | ||
<body> | ||
<h1>{title}</h1> | ||
</body> | ||
</html> |
27 changes: 27 additions & 0 deletions
27
packages/astro/test/fixtures/dynamic-route-collision/src/pages/[aOrder].astro
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
--- | ||
export async function getStaticPaths() { | ||
const pages = [ | ||
{ | ||
page: 'order', | ||
title: 'Order from A', | ||
}, | ||
]; | ||
return pages.map(({ page, title }) => { | ||
return { | ||
params: { 'aOrder': page }, | ||
props: { title }, | ||
}; | ||
}); | ||
} | ||
const { title } = Astro.props; | ||
--- | ||
|
||
<html> | ||
<head> | ||
<title>{title}</title> | ||
</head> | ||
<body> | ||
<h1>{title}</h1> | ||
</body> | ||
</html> |
27 changes: 27 additions & 0 deletions
27
packages/astro/test/fixtures/dynamic-route-collision/src/pages/[bOrder].astro
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
--- | ||
export async function getStaticPaths() { | ||
const pages = [ | ||
{ | ||
page: 'order', | ||
title: 'Order from B', | ||
}, | ||
]; | ||
return pages.map(({ page, title }) => { | ||
return { | ||
params: { 'bOrder': page }, | ||
props: { title }, | ||
}; | ||
}); | ||
} | ||
const { title } = Astro.props; | ||
--- | ||
|
||
<html> | ||
<head> | ||
<title>{title}</title> | ||
</head> | ||
<body> | ||
<h1>{title}</h1> | ||
</body> | ||
</html> |
28 changes: 28 additions & 0 deletions
28
packages/astro/test/fixtures/dynamic-route-collision/src/pages/[locale]/[...page].astro
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
--- | ||
export async function getStaticPaths() { | ||
const pages = [ | ||
{ | ||
locale: 'en', | ||
page: undefined, | ||
title: 'Dynamic+Rest Localized Index', | ||
}, | ||
]; | ||
return pages.map(({ page, locale, title }) => { | ||
return { | ||
params: { page, locale }, | ||
props: { title }, | ||
}; | ||
}); | ||
} | ||
const { title } = Astro.props; | ||
--- | ||
|
||
<html> | ||
<head> | ||
<title>{title}</title> | ||
</head> | ||
<body> | ||
<h1>{title}</h1> | ||
</body> | ||
</html> |
27 changes: 27 additions & 0 deletions
27
packages/astro/test/fixtures/dynamic-route-collision/src/pages/[locale]/index.astro
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
--- | ||
export async function getStaticPaths() { | ||
const pages = [ | ||
{ | ||
locale: 'en', | ||
title: 'Dynamic-only Localized Index', | ||
}, | ||
]; | ||
return pages.map(({ page, locale, title }) => { | ||
return { | ||
params: { page, locale }, | ||
props: { title }, | ||
}; | ||
}); | ||
} | ||
const { title } = Astro.props; | ||
--- | ||
|
||
<html> | ||
<head> | ||
<title>{title}</title> | ||
</head> | ||
<body> | ||
<h1>{title}</h1> | ||
</body> | ||
</html> |
31 changes: 31 additions & 0 deletions
31
packages/astro/test/fixtures/dynamic-route-collision/src/pages/[page].astro
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
--- | ||
export async function getStaticPaths() { | ||
const pages = [ | ||
{ | ||
page: 'about', | ||
title: 'Dynamic About', | ||
}, | ||
{ | ||
page: 'blog', | ||
title: 'Dynamic Blog', | ||
}, | ||
]; | ||
return pages.map(({ page, title }) => { | ||
return { | ||
params: { page }, | ||
props: { title }, | ||
}; | ||
}); | ||
} | ||
const { title } = Astro.props; | ||
--- | ||
|
||
<html> | ||
<head> | ||
<title>{title}</title> | ||
</head> | ||
<body> | ||
<h1>{title}</h1> | ||
</body> | ||
</html> |
8 changes: 8 additions & 0 deletions
8
packages/astro/test/fixtures/dynamic-route-collision/src/pages/about.astro
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
<html> | ||
<head> | ||
<title>Static About Page</title> | ||
</head> | ||
<body> | ||
<h1>Static About</h1> | ||
</body> | ||
</html> |
8 changes: 8 additions & 0 deletions
8
packages/astro/test/fixtures/dynamic-route-collision/src/pages/index.astro
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
<html> | ||
<head> | ||
<title>Static Index Page</title> | ||
</head> | ||
<body> | ||
<h1>Static Index</h1> | ||
</body> | ||
</html> |
27 changes: 27 additions & 0 deletions
27
packages/astro/test/fixtures/dynamic-route-collision/src/pages/tags/[...page].astro
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
--- | ||
export async function getStaticPaths() { | ||
const pages = [ | ||
{ | ||
page: undefined, | ||
title: 'Rest Tag Index', | ||
}, | ||
]; | ||
return pages.map(({ page, title }) => { | ||
return { | ||
params: { tag: page }, | ||
props: { title }, | ||
}; | ||
}); | ||
} | ||
const { title } = Astro.props; | ||
--- | ||
|
||
<html> | ||
<head> | ||
<title>{title}</title> | ||
</head> | ||
<body> | ||
<h1>{title}</h1> | ||
</body> | ||
</html> |
8 changes: 8 additions & 0 deletions
8
packages/astro/test/fixtures/dynamic-route-collision/src/pages/tags/index.astro
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
<html> | ||
<head> | ||
<title>Static Tags Index</title> | ||
</head> | ||
<body> | ||
<h1>Static Tags Index</h1> | ||
</body> | ||
</html> |
8 changes: 8 additions & 0 deletions
8
packages/astro/test/fixtures/dynamic-route-collision/src/pages/who.astro
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
<html> | ||
<head> | ||
<title>Static Who We Are</title> | ||
</head> | ||
<body> | ||
<h1>Static Who We Are</h1> | ||
</body> | ||
</html> |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.