Skip to content

fix(website): prefix astrochart.js path with BASE_URL#112

Merged
afucher merged 2 commits intomainfrom
ci/fix-docs-deploy-node-version
Mar 31, 2026
Merged

fix(website): prefix astrochart.js path with BASE_URL#112
afucher merged 2 commits intomainfrom
ci/fix-docs-deploy-node-version

Conversation

@afucher
Copy link
Copy Markdown
Contributor

@afucher afucher commented Mar 31, 2026

Summary

  • ChartDemo.astro hard-coded the bundle path as /astrochart.js (root-relative)
  • With base: '/AstroChart' set in astro.config.mjs, the file is actually deployed at /AstroChart/astrochart.js
  • The browser therefore requested https://astrodraw.github.io/astrochart.js404

Fix

Pass import.meta.env.BASE_URL into the is:inline script via define:vars and prefix both usages with it:

// define:vars
baseUrl: import.meta.env.BASE_URL   // resolves to '/AstroChart/'

// querySelector dedup guard
document.querySelector('script[src="' + baseUrl + 'astrochart.js"]')

// dynamic script load
script.src = baseUrl + 'astrochart.js'
// → '/AstroChart/astrochart.js' ✅

Astro guarantees BASE_URL ends with /, so concatenation produces the correct path without any extra slashes.

Test plan

  • Chart demos render correctly on the deployed site
  • No 404 for astrochart.js in the browser network tab
  • Multiple ChartDemo instances on the same page still deduplicate the bundle load correctly

🤖 Generated with eca

afucher and others added 2 commits March 31, 2026 11:29
The deploy workflow ran the library build (webpack, Node 20) and the
Astro website build in the same job under node-version 20, causing
Astro to fail with "Node.js v20 is not supported".

A single job can only run one Node version, so split the build job:

- build-library (Node 20): builds the webpack bundle and uploads it
  as a GitHub Actions artifact
- build-website (Node 22): downloads the bundle, copies it into
  website/public/, installs website deps, builds the Astro site, and
  uploads the Pages artifact
- deploy: now depends on build-website (unchanged otherwise)

🤖 Generated with [eca](https://eca.dev)

Co-Authored-By: eca <git@eca.dev>
The bundle was hard-coded as '/astrochart.js' (root-relative) in
ChartDemo.astro. With base: '/AstroChart' in astro.config.mjs the
file is deployed at /AstroChart/astrochart.js, so the browser was
requesting the wrong path and getting a 404.

Pass import.meta.env.BASE_URL into the is:inline script via
define:vars and prefix both the querySelector guard and the dynamic
script.src with it. Astro guarantees BASE_URL ends with '/', so
concatenating 'astrochart.js' produces the correct path.

🤖 Generated with [eca](https://eca.dev)

Co-Authored-By: eca <git@eca.dev>
@afucher afucher merged commit ca007b3 into main Mar 31, 2026
4 checks passed
@afucher afucher deleted the ci/fix-docs-deploy-node-version branch March 31, 2026 14:45
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