-
Notifications
You must be signed in to change notification settings - Fork 6
Description
Describe the bug
Issue Description
The graph visualization on the landing page fails to load when the SPACESHIP_BASE environment variable or base config option is set to "/" (root path).
Root Cause
The bug is in the GraphView.astro component's URL construction logic (line 59-60). When base="/", the current implementation creates a malformed URL:
Current code:
const base = this.getAttribute("base");
const slug = this.getAttribute("slug");
const url = base ? `/${base.replace(/^\/+|\/+$/g, '')}/_spaceship/graph/${slug ?? "index"}.json` : `/_spaceship/graph/${slug ?? "index"}.json`;What happens when base="/":
base.replace(/^\/+|\/+$/g, '')strips leading/trailing slashes from"/", resulting in an empty string""- The ternary condition
base ? ...is still truthy (becausebaseis"/", notnullorundefined) - The URL becomes:
/${""}/_spaceship/graph/index.json→///_spaceship/graph/index.json - This triple-slash URL is invalid and causes the fetch to fail
- No graph data loads, so the graph doesn't render
Expected Behavior
When base="/", the graph should load from /_spaceship/graph/index.json (same as when base is undefined).
Proposed Fix
Modify the URL construction to check the normalized base path instead of the raw base attribute:
const base = this.getAttribute("base");
const slug = this.getAttribute("slug");
const normalizedBase = base ? base.replace(/^\/+|\/+$/g, '') : '';
const url = normalizedBase
? `/${normalizedBase}/_spaceship/graph/${slug ?? "index"}.json`
: `/_spaceship/graph/${slug ?? "index"}.json`;This ensures:
- When
base="/"→normalizedBase=""→ URL is/_spaceship/graph/index.json✅ - When
base="/subpath"→normalizedBase="subpath"→ URL is/subpath/_spaceship/graph/index.json✅ - When
baseis undefined/null →normalizedBase=""→ URL is/_spaceship/graph/index.json✅
File to Change
File: components/GraphView/GraphView.astro
Lines: 59-60
Before:
async loadData(): Promise<GraphViewData> {
const base = this.getAttribute("base");
const slug = this.getAttribute("slug");
const url = base ? `/${base.replace(/^\/+|\/+$/g, '')}/_spaceship/graph/${slug ?? "index"}.json` : `/_spaceship/graph/${slug ?? "index"}.json`;
const response = await fetch(url);
return response.json();
}After:
async loadData(): Promise<GraphViewData> {
const base = this.getAttribute("base");
const slug = this.getAttribute("slug");
const normalizedBase = base ? base.replace(/^\/+|\/+$/g, '') : '';
const url = normalizedBase
? `/${normalizedBase}/_spaceship/graph/${slug ?? "index"}.json`
: `/_spaceship/graph/${slug ?? "index"}.json`;
const response = await fetch(url);
return response.json();
}How to Reproduce
- Set
SPACESHIP_BASE="/"in your.envfile, or setbase: "/"inwebsite.config.json - Run the dev server
- Navigate to the landing page
- Observe that the graph visualization doesn't load
- Check browser console/network tab - you'll see a failed fetch to
///_spaceship/graph/index.json
Environment
- astro-spaceship version: (latest from node_modules)
- Astro version: 5.12.8
- Browser: Any
This explanation provides:
- Clear problem description - what fails and when
- Root cause analysis - why the bug occurs with code walkthrough
- Proposed solution - exact code changes needed
- Reproduction steps - how to verify the bug
- Expected vs actual behavior - what should happen
Would you like me to format this as a GitHub issue, pull request description, or another format?
To Reproduce
Steps to Reproduce
- Set
SPACESHIP_BASE="/"in your.envfile or"base": "/"inwebsite.config.json - Run
npm run devorbun dev - Open the landing page in your browser
- Observe that the graph visualization area is empty/doesn't load
- Check browser DevTools → Network tab for a failed request to
///_spaceship/graph/index.json(note the invalid triple slash)
Expected: Graph should load from /_spaceship/graph/index.json and display nodes/connections
Actual: Graph fails to load due to malformed URL
Expected behavior
No response
Screenshots
No response
Additional context
No response
Code of Conduct
- I agree to follow this project's Code of Conduct