Skip to content

Commit f897702

Browse files
authored
chore(vercel): use absolute hrefs in preview dir indexes (#31106)
Issue number: internal --------- <!-- Please do not submit updates to dependencies unless it fixes an issue. --> <!-- Please try to limit your pull request to one type (bugfix, feature, etc). Submit multiple pull requests if needed. --> ## What is the current behavior? `generate_dir_index` in `core/scripts/vercel-build.sh` writes child links like `<a href="basic/">` and an up-link `<a href="../">`. Vercel doesn't 308-redirect to add a trailing slash, so visiting a preview directory URL like `/src/components/progress-bar/test` (no slash) returns the index page but the browser resolves `basic/` against the parent directory. That path doesn't exist, and Vercel's fallback serves the root landing page, so navigation looks like it "circles back" to the preview home instead of opening the test scenario. ## What is the new behavior? The dir-index generator now emits absolute hrefs based on the directory's `url_path`, including the `../` up-link. Trailing-slash quirks no longer affect navigation between component test scenarios on Vercel previews. ## Does this introduce a breaking change? - [ ] Yes - [x] No <!-- If this introduces a breaking change: 1. Describe the impact and migration path for existing applications below. 2. Update the BREAKING.md file with the breaking change. 3. Add "BREAKING CHANGE: [...]" to the commit description when merging. See https://github.com/ionic-team/ionic-framework/blob/main/docs/CONTRIBUTING.md#footer for more information. --> ## Other information Test page: - https://ionic-framework-git-fix-vercel-preview-links-ionic1.vercel.app/src/components/progress-bar/test Versus the broken version on main: - https://ionic-framework-git-main-ionic1.vercel.app/src/components/progress-bar/test
1 parent d26017f commit f897702

1 file changed

Lines changed: 8 additions & 2 deletions

File tree

core/scripts/vercel-build.sh

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,12 @@ generate_dir_index() {
6262
# Skip if an index.html already exists (it's an actual test page)
6363
[ -f "${dir}/index.html" ] && return
6464

65+
# Absolute hrefs based on url_path. Vercel does not redirect to add trailing
66+
# slashes, so a relative href like "basic/" from a URL without a trailing
67+
# slash resolves against the parent directory and breaks navigation.
68+
local parent_path="${url_path%/}"
69+
parent_path="${parent_path%/*}/"
70+
6571
local entries=""
6672
for child in "${dir}"/*/; do
6773
[ -d "${child}" ] || continue
@@ -70,7 +76,7 @@ generate_dir_index() {
7076
case "${name}" in *-snapshots|.*) continue ;; esac
7177
# Only include if there's at least one index.html somewhere underneath
7278
find "${child}" -name "index.html" -print -quit | grep -q . || continue
73-
entries="${entries}<a href=\"${name}/\">${name}/</a>\n"
79+
entries="${entries}<a href=\"${url_path}${name}/\">${name}/</a>\n"
7480
done
7581

7682
[ -z "${entries}" ] && return
@@ -92,7 +98,7 @@ generate_dir_index() {
9298
</head>
9399
<body>
94100
<h1>Index of ${url_path}</h1>
95-
<a class="up" href="../">../</a>
101+
<a class="up" href="${parent_path}">../</a>
96102
$(echo -e "${entries}")
97103
</body>
98104
</html>

0 commit comments

Comments
 (0)