Skip to content

Commit 6d11508

Browse files
fix: Fix css loading on direct links (#31)
This pull request introduces several improvements and fixes related to asset handling, CSS layer ordering, and proxy compatibility for the documentation marketplace. The main changes focus on ensuring consistent CSS rendering, correct asset resolution when served from sub-paths, and preventing encoding issues with proxies and gateways. **Asset handling and CSS fixes:** * In `scripts/build-vite.js`, the asset copy logic now rewrites root-relative `url()` references in CSS bundles (e.g., `url(/fonts/...)`) to relative paths (e.g., `url(../fonts/...)`). This ensures that CSS assets resolve correctly when the app is served from a sub-path, such as `/knowledge-base/{slug}/_astro/`. * Added `writeFileSync` import to support the CSS rewriting logic in the build script. **CSS layer ordering:** * In `src/layouts/Base.astro`, a fix was added to declare `@layer base` before sub-app stylesheets are slotted in. This guarantees that Tailwind's base layer has lower priority than Starlight's content layers, ensuring heading sizes and other styles render correctly on both direct page loads and client-side navigation. **Proxy and gateway compatibility:** * In `nginx.conf`, the `gzip_proxied` directive is now set to `off` to prevent nginx from gzip-encoding responses to proxies or gateways that already sent `Accept-Encoding` upstream. This avoids issues where the `Content-Encoding` header could be leaked to the browser, causing decoding errors. * Added a `Cache-Control: no-transform` header for `/knowledge-base/` routes in `nginx.conf` to instruct intermediate proxies (like FragmentGateway) not to transcode or re-encode responses, further preventing encoding mismatches. **Dependency updates:** * Updated `@astrojs/check` development dependency from `^0.9.9` to `^0.9.10` in `package.json`. **Release notes:** * Fix css loading on direct links **Related:** Closes #30
2 parents 5085e73 + 3b3715f commit 6d11508

5 files changed

Lines changed: 820 additions & 649 deletions

File tree

nginx.conf

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,10 @@ server {
88
# ── Compression ───────────────────────────────────────────────────────────
99
gzip on;
1010
gzip_vary on;
11-
gzip_proxied any;
11+
# "off" prevents nginx from gzip-encoding responses to proxies/gateways that
12+
# already sent Accept-Encoding upstream. FragmentGateway decompresses server-side
13+
# but can leak Content-Encoding header to the browser causing ERR_CONTENT_DECODING_FAILED.
14+
gzip_proxied off;
1215
gzip_comp_level 6;
1316
gzip_types
1417
text/css
@@ -66,6 +69,10 @@ server {
6669
# Strip the /knowledge-base/ prefix so files resolve from the dist root.
6770
location ^~ /knowledge-base/ {
6871
rewrite ^/knowledge-base/(.*)$ /$1 break;
72+
# Tell any intermediate proxy (e.g. web-fragments FragmentGateway) not to
73+
# transcode/re-encode this response. Prevents Content-Encoding header
74+
# leakage when the gateway auto-decompresses but still forwards the header.
75+
add_header Cache-Control "no-transform" always;
6976
try_files $uri $uri/index.html =404;
7077
}
7178

0 commit comments

Comments
 (0)