-
-
Notifications
You must be signed in to change notification settings - Fork 2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
fix: always default paths.assets
to paths.base
#8928
Conversation
… outside the base path + add tests [1/2]
… outside the base path + add tests [2/2]
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you! This was probably caused through #8838 (since the issue says it starts erroring on 1.4 or later), but I don't fully understand how. @benmccann @Rich-Harris maybe you can have a closer look as well.
packages/kit/test/prerendering/paths-base/src/routes/+layout.js
Outdated
Show resolved
Hide resolved
Co-authored-by: Simon H <5968653+dummdidumm@users.noreply.github.com>
thank you! the actual fix was a bit different, but the failing test was super helpful for diagnosing it |
paths.assets
to paths.base
my bad. I swear I had the code written as Rich has it now because that's how it was before my change. I must have accidentally lost it at some point. glad we have a test for it now! thank you! |
Please don't delete this checklist! Before submitting the PR, please make sure you do the following:
Tests
pnpm test
and lint the project withpnpm lint
andpnpm check
tests/prerendering/paths-base
was modified to reproduce the behavior in the issue linked below, which fails before the fix and passes after.Changesets
pnpm changeset
and following the prompts. Changesets that add features should beminor
and those that fix bugs should bepatch
. Please prefix changeset messages withfeat:
,fix:
, orchore:
.This fixes the issue discussed in #8919 where the build process will fail if
trailingSlash = 'never'
in the root page and apaths.base
is set. Essentially, the build process would eat the last element of the base path and subsequently error out.When
trailingSlash = 'never';
, when prerendering/$base/
(our root), the prerenderer gets redirected to'/$base'
atprerender.js:305
(which strikes me as invalid, it's kind of "before the root"). Then, that will cause us to visit/$base
, which will return the HTML we want rendered at the/$base
. This is a problem though, because at this point all relative links we crawl will be resolved relative to/$base
, so when we callresolve
atprerender.js:250
with, for example,./favicon.png
, we'll end up with a call likeresolve('/$base', './favicon.png')
, which will ofc resolve to/favicon.png
(and not/$base/favicon.ico
, which is what we want).This was resolved by adding a special case in
prerender.js
'svisit
function that, if the current URL matches theconfig.paths.base
url exactly, then it will add a trailing slash (causing relative paths to resolve as children to the root/base directory rather than as siblings).