-
-
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
dynamic base #9150
dynamic base #9150
Conversation
Thank you! We will need to get the tests in |
I wonder if there might be a simpler way than computing the base everywhere we instantiate the application. In
Perhaps in the beginning of |
Is it not already doing that ? we need it to be executed once per page load and with the current code in that PR it does exactly that by having it executed in the index.html It uses the same technique used by |
You said we still need to "fix the pre-rendered html and js file to use relative paths". I'm not entirely sure what needs to be fixed there, but was hoping the method Rich suggested would avoid solve that.
It looks like @Rich-Harris just added that two days ago in #8957. We probably should not implement it that way as it's going to break things like Storybook and Vitest. They'll import components directly without instantiating an entire application and so globals defined in the page won't be available. We should probably setup some sort of test to stop these sorts of regressions. In the meantime, I'd rather not double down on that implementation. |
Oh the extra step are still needed because currently that solution only set the base value (but now dynamically) that we can then get by using Also the extra step allow the sveltekit app to still work when no javascript is running by replacing all absolute path svelte generate into relative one
ok, yes once the new thing is in, we can adapt to ensure base and assets are set dynamicaly |
You can ignore my earlier comment about the alternate implementation in #9150 (comment). The way this PR is implemented is basically correct. For an explanation to my later self and other readers, I believe if we are serving a fallback page there is no way to have a dynamic base path because I'm not sure how the client would differentiate the part of the request path that is the base path vs the route path. If a page is prerendered or dynamically rendered then we can calculate the distance from the base at render time in order to set the However, the I think what we should do is set the base path the traditional way in the virtual module most of the time and just use this new relative method if prerendering or rendering a fallback page. The easiest option would probably be to access |
An app can contain prerendered and non-prerendered pages, so that's not an option. If referencing |
Oh yeah, for some reason I was thinking the virtual module was a per-request thing, but I guess it's a per-app thing. The kids got me sick for like the fifth time since Thanksgiving, so my head's not been working too well. I feel like the |
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.
does this need a changeset?
otherwise, lgtm. I'll fix the virtual module thing in another PR after I figure out what's going on with #9162
Added hardcoded fallbacks — this should solve the Vitest case. I think we can solve the prerendering case easily enough. In fact the pre is a red herring, as the solution applies equally to content that is rendered on demand. Made a start in #9220 — might be nice to get that in as part of this, so it's a single minor release. |
Implemented in #9220 |
Thank you for driving this feature!! It wouldn't have gotten done without your efforts |
Implement dynamic base like assets is currently handled
this is one step more for #595
The only extra step required after this PR is in, is to fix the pre-rendered html and js file to use relative paths
See : https://github.com/bug-reproduction/svelte-kit-static-ipfs/tree/fixes#fixes and https://github.com/wighawag/sveltejs-adapter-ipfs
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
3 test seems to fail but they do not seem to be related
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:
.