Skip to content

fix: render a readme's relative links against its own branch - #8411

Merged
alexander-akait merged 1 commit into
mainfrom
fix/rendered-readme-links-on-main
Sep 14, 2026
Merged

alexander-akait merged 1 commit into
mainfrom
fix/rendered-readme-links-on-main

Conversation

@alexander-akait

Copy link
Copy Markdown
Member

Summary

Loader and plugin pages are generated from each package's readme, and processReadme resolves the readme's relative links against the page it is rendered at. It built that page url by inserting blob/ in front of the literal master:

const renderedUrl = sourceUrl
  .replace(/raw.githubusercontent.com/, "github.com")
  .replace(/master/, "blob/master");

A repository on main matches nothing, so no blob/ is inserted and every relative link resolves to https://github.com/<owner>/<repo>/main/<path> — not a url GitHub serves. Same function, two branches:

master  -> [LICENSE](https://github.com/webpack/some-webpack-plugin/blob/master/LICENSE)
main    -> [LICENSE](https://github.com/webpack/some-webpack-plugin/main/LICENSE)

This is not an edge case: of the repositories the site generates pages from, the nine I sampled are all on main — less-loader, sass-loader, postcss-loader, stylus-loader, terser-webpack-plugin, minimizer-webpack-plugin, diagnostics-webpack-plugin, babel-loader, svg-chunk-webpack-plugin. A [LICENSE](./LICENSE) link sits at the bottom of nearly every one of those readmes.

I found it while checking that diagnostics-webpack-plugin's page would render correctly after the rename — its readme links CHANGELOG.md and ./LICENSE, and both came out broken.

The branch is read from the raw url now, whatever it is called, so the rendered url is built rather than patched. As a side effect an owner or repository whose name contains master is no longer rewritten by accident.

Tests

npx jest — 25 suites, 105 tests, all passing.

Worth a look in review: the suite pinned the bug. "rewrite relative url" asserted the main url without blob/ as the expected output, so the broken link was encoded as correct. That expectation now names the link that resolves, and a new case covers master, main and next together.

lint:prose could not run here — vale is not installed in this environment — but this diff touches no src/content prose. lint:js, lint:prettier, lint:markdown and lint:spelling all pass.

Use of AI

AI was used. It rendered the plugin readme through processReadme while verifying the page after a rename, noticed the rewritten links were wrong, reduced it to the master/main pair above, sampled the repositories' default branches to see how far it reached, then wrote the fix and the test and corrected the expectation that had pinned it.

🤖 Generated with Claude Code

https://claude.ai/code/session_01GzZci4NQeiqwdrVfd7dGXy


Generated by Claude Code

`processReadme` turns a raw readme url into the page it is rendered at so
that relative links resolve, and it did that by inserting `blob/` in front
of the literal `master`:

    .replace(/master/, "blob/master")

A repository on `main` therefore got no `blob/` at all, and every relative
link in its readme resolved to `github.com/<owner>/<repo>/main/<path>`,
which is not a url GitHub serves. Of the loader and plugin repositories
the site generates pages from, the nine sampled are all on `main` —
including `diagnostics-webpack-plugin`, whose readme links `CHANGELOG.md`
and `./LICENSE`.

The branch is read from the raw url now, whatever it is called, so the
rendered url is built rather than patched. A repository or owner whose
name contains `master` is no longer rewritten by accident either.

The suite pinned the old behaviour: "rewrite relative url" asserted the
`main` url without `blob/` as what it should be. It asserts the link that
resolves now, and a new case covers `master`, `main` and `next` together.
@vercel

vercel Bot commented Sep 14, 2026 •

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated
webpack-js-org Ready Ready Preview Sep 14, 2026 4:44pm UTC

Request Review

@alexander-akait
alexander-akait merged commit 71ad837 into main Sep 14, 2026
12 checks passed
@alexander-akait
alexander-akait deleted the fix/rendered-readme-links-on-main branch September 14, 2026 18:11

This branch was successfully deployed

1 active deployment
Preview — 9171127d Deployed Sep 14, 2026 by vercel[bot]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant