CDN assets support - #2319
Open
indeyets wants to merge 6 commits into
Open
Conversation
Vite's base may be a full URL. pathe's join, used since solidjs#2305 to prefix asset paths with it, folded its "://" into ":/", so every entry, stylesheet, modulepreload and serialized manifest path came out as https:/…
With a full URL as Vite's base, server functions post to the CDN and no-JS redirects resolve against it. `SERVER_BASE_URL` is the right place for the app base, but it is empty unless `server.baseURL` is set.
Vite accepts `base: "https://cdn…/"` for CDN hosting, and server functions used it as the app origin. An external base says where the assets are and nothing about the app, so the app stays at the root, in dev as well: Vite reduces such a base to its path there, and 2.0.5 happened to mount the app under it. `SERVER_BASE_URL` has named the app base since solidjs#2218, but only API route matching read it, and only when `server.baseURL` was set.
Relative redirect locations are resolved against origin + base, and
`new URL("page", "http://host/app")` gives /page, dropping the mount
segment. The base here comes from the user config, before Vite
normalizes it.
Apps pass it to the router as `base`, see https://docs.solidjs.com/solid-start/building-your-application/routing, but it was declared only in the package's internal env.d.ts, so apps saw it as `any`.
Passing `base` to the router is what an app under a path needs; at `/` it is a no-op, so the existing suites are unaffected.
🦋 Changeset detectedLatest commit: 45001d8 The changes in this PR will be included in the next version bump. This PR includes changesets to release 1 package
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
✅ Deploy Preview for solid-start-landing-page ready!
To edit notification comments on pull requests, go to your Netlify project configuration. |
commit: |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
PR Checklist
Please check if your PR fulfills the following requirements:
What is the current behavior?
Vite accepts a full URL as
base(https://cdn.example.com/some/prefix/) so that a build addresses its assets on a CDN. With @solidjs/start 2.0.5 that config produces a broken build:BASE_URLwith the asset path viapathe.join, which foldshttps://intohttps:/. Every<link>, modulepreload, the entry<script>and the serialized manifest come out ashttps:/cdn.example.com/…. The prefixing itself was added in fix: respect Vite base in production asset URLs #2305; it only works for a path base.${BASE_URL}_server, i.e. to the CDN. The no-JS form fallback and the single-flight referer resolve againstorigin + BASE_URL, which for a full URL yields hosts likehttp://app.example.comhttps/….SERVER_BASE_URLhas existed since fix: match API routes under server base URL #2218 as the app's mount path, but only API route matching read it, and only whenserver.baseURLwas set explicitly. Otherwise it was"", and everything fell back to the asset base.Related: #1132 (closed, 1.x) described the same conflation of asset base and app base.
What is the new behavior?
BASE_URLaddresses assets only.SERVER_BASE_URLis the app's mount path and is always defined:server.baseURLif set;/when Vite'sbaseis a full or protocol-relative URL;baseitself (a plain path).It is always wrapped in slashes, so relative redirect
Locations resolve under it. Server functions, no-JS redirects, single flight and API route matching all use it. The SSR manifest joins asset paths with a URL-aware helper, so a full-URL base comes through intact. The type is published via@solidjs/start/env, since apps pass it to<Router base>(the documented setup for an app under a path).Verified with a build using
base: "https://cdn.example.com/": all asset tags, imported assets and CSSurl()s point at the CDN,_serverstays at/. Withbase: "/app/"everything stays under/app/as before.The changes are split into six commits, each meant to be reviewed on its own; the manifest fix comes first and is independent of the rest.