Commit f61a039
authored
Fix mirrored link rewriting for TanStack examples (#4320)
### Motivation
- Mirrored example pages could incorrectly rewrite links pointing to a
different origin into internal marketplace routes, producing wrong
"mirrored from" URLs for TanStack examples.
- The intent is to preserve external-origin links (e.g. `github.com`)
and only rewrite links that are on the same origin as the mirrored
source (e.g. `raw.githubusercontent.com`).
### Description
- In `packages/website-v2/src/marketplace/marketplaceData.ts` compute
the page `baseOrigin` and added a `getUrlOrigin` helper.
- In `resolveHtmlAssetLinks` skip mapping an `href` to a marketplace
route when the resolved link's origin differs from the page origin and
return the original resolved URL instead.
- Added a unit test in
`packages/website-v2/src/marketplace/marketplaceData.test.ts` that
asserts links pointing to a different origin are not rewritten to
internal routes.
### Testing
- Added a unit test `does not rewrite links that point to a different
origin` in `packages/website-v2/src/marketplace/marketplaceData.test.ts`
to cover the new behavior.
- No automated test suite was executed as part of this change (tests
added but not run).
------
[Codex
Task](https://chatgpt.com/codex/tasks/task_e_6973be5762848326946f723cbaae5cb2)
<!-- CURSOR_SUMMARY -->
---
> [!NOTE]
> Ensures mirrored pages only rewrite links on the same origin as the
source, preventing incorrect internal routing for external links (e.g.,
GitHub).
>
> - In `resolveHtmlAssetLinks`, compute `baseOrigin` and compare with
`targetOrigin`; if origins differ, keep the resolved external URL
> - Added `getUrlOrigin` helper to safely extract URL origins
> - Added unit test `does not rewrite links that point to a different
origin` in `marketplaceData.test.ts` verifying external links remain
unchanged
>
> <sup>Written by [Cursor
Bugbot](https://cursor.com/dashboard?tab=bugbot) for commit
3fffdea. This will update automatically
on new commits. Configure
[here](https://cursor.com/dashboard?tab=bugbot).</sup>
<!-- /CURSOR_SUMMARY -->1 parent 356ae43 commit f61a039
File tree
2 files changed
+32
-0
lines changed- packages/website-v2/src/marketplace
2 files changed
+32
-0
lines changedLines changed: 19 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
200 | 200 | | |
201 | 201 | | |
202 | 202 | | |
| 203 | + | |
| 204 | + | |
| 205 | + | |
| 206 | + | |
| 207 | + | |
| 208 | + | |
| 209 | + | |
| 210 | + | |
| 211 | + | |
| 212 | + | |
| 213 | + | |
| 214 | + | |
| 215 | + | |
| 216 | + | |
| 217 | + | |
| 218 | + | |
| 219 | + | |
| 220 | + | |
| 221 | + | |
203 | 222 | | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
355 | 355 | | |
356 | 356 | | |
357 | 357 | | |
| 358 | + | |
358 | 359 | | |
359 | 360 | | |
360 | 361 | | |
| |||
364 | 365 | | |
365 | 366 | | |
366 | 367 | | |
| 368 | + | |
| 369 | + | |
| 370 | + | |
| 371 | + | |
367 | 372 | | |
368 | 373 | | |
369 | 374 | | |
| |||
393 | 398 | | |
394 | 399 | | |
395 | 400 | | |
| 401 | + | |
| 402 | + | |
| 403 | + | |
| 404 | + | |
| 405 | + | |
| 406 | + | |
| 407 | + | |
| 408 | + | |
396 | 409 | | |
397 | 410 | | |
398 | 411 | | |
| |||
0 commit comments