feat(start): support serving assets via relative base urls#7572
feat(start): support serving assets via relative base urls#7572EduardF1 wants to merge 1 commit into
Conversation
📝 WalkthroughWalkthroughThis PR adds support for relative base URL deployments by normalizing asset paths at both build and runtime. Build-time normalization in the manifest builder ensures relative basePaths produce relative asset paths, while runtime normalization in the Script component preserves relative URLs in non-HTTP environments like iFrames. ChangesRelative Base URL Support
🎯 2 (Simple) | ⏱️ ~10 minutes Suggested labels
Poem
🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
🧹 Nitpick comments (1)
packages/react-router/src/Asset.tsx (1)
142-144: Preserve../relativesrconly if inputs can generate it
- Search in
packages/start-plugin-core/src/start-manifest-plugin/shows../only in internal import paths (not generated manifesthref/src), and thepackages/react-router/scan found nosrc.*../literals.packages/react-router/src/Asset.tsxcurrently preserves onlyattrs.src.startsWith('./');../...would be normalized vianew URL(attrs.src, base).href. Keep the../preservation as a follow-up only if embedded/iframe use-cases can supply../...asattrs.src(add a test if so).🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@packages/react-router/src/Asset.tsx` around lines 142 - 144, The current Asset.tsx logic preserves only relative src values that start with "./" but not "../"; update the code by keeping the existing behavior (do not add preservation for "../" paths) and add a concise inline comment near the attrs.src handling (in the Asset component / function that checks attrs.src.startsWith('./')) stating why "../" is deliberately not preserved and that "../" should only be added later if a real input source can produce it (with a test at that time); do not change normalization via new URL(attrs.src, base).href now.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Nitpick comments:
In `@packages/react-router/src/Asset.tsx`:
- Around line 142-144: The current Asset.tsx logic preserves only relative src
values that start with "./" but not "../"; update the code by keeping the
existing behavior (do not add preservation for "../" paths) and add a concise
inline comment near the attrs.src handling (in the Asset component / function
that checks attrs.src.startsWith('./')) stating why "../" is deliberately not
preserved and that "../" should only be added later if a real input source can
produce it (with a test at that time); do not change normalization via new
URL(attrs.src, base).href now.
ℹ️ Review info
⚙️ Run configuration
Configuration used: defaults
Review profile: CHILL
Plan: Pro
Run ID: be0d6972-badd-43dc-bcb2-b4a75599958a
📒 Files selected for processing (2)
packages/react-router/src/Asset.tsxpackages/start-plugin-core/src/start-manifest-plugin/manifestBuilder.ts
Description
Fixes #5966
When TanStack Start is configured with a relative base path (
base: './') to be hosted inside sub-directory setups or iFrames (e.g., Home Assistant add-ons), the asset loader was incorrectly discarding the relative dot and prepending a root slash. Further,Asset.tsxresolved allhrefURLs absolutely against the browser's origin vianew URL(...), destroying the relativity.This patch:
manifestBuilder.tswithout overriding the./prefix.Asset.tsxwhen the path is explicitly relative and running in a document where baseURI isn't strictly absolute.Testing
Verified output generated by standard build command.
Summary by CodeRabbit