-
-
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
[feat] pass ComponentLoader
to handle
#2663
Conversation
🦋 Changeset detectedLatest commit: e5723d9 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 |
ViteLoader
to resolve
ViteLoader
to resolve
ComponentLoader
to resolve
f2ef5d7
to
e1eea0b
Compare
ComponentLoader
to resolve
ComponentLoader
to handle
aee990b
to
6424a96
Compare
6424a96
to
7727e74
Compare
7727e74
to
e5723d9
Compare
Been having a blast experimenting with this today. It seems there are two approaches for adding third party routers (sorry if I'm stating the obvious): Option A - loadComponenthooks.js import { Router, createRouter } from '@roxi/routify'
import routes from '../.routify/routes.default.js'
/** @type {import('@sveltejs/kit').Handle} */
export async function handle({ request, loader }) {
// create a router instance
const router = createRouter({ routes })
// let router run async functions, eg. fetch dynamic imports, run preloads, guards etc.
await router.url.replace(request.path)
// create SSR node
const ssrNode = await loader.loadComponent({ id: 'src/routes/root.svelte' });
// inject the router into `src/routes/root.svelte`
const rendered = ssrNode.module.default.render({ router });
... src/routes/root.svelte <script>
import { Router } from '@roxi/routify'
export let router
</script>
<Router {router} /> Option B - plain SSRhooks.js import { Router, createRouter } from '@roxi/routify'
import routes from '../.routify/routes.default.js'
/** @type {import('@sveltejs/kit').Handle} */
export async function handle({ request, loader }) {
const router = createRouter({ routes })
await router.url.replace(request.path)
const rendered = Router.render({router}) Option B doesn't require a |
Option B will not return the list of JS and CSS files needed to populate the page's |
I'm afraid I think this is a bit of a non-starter, aside from whether it's a desirable API — it makes server-side code-splitting completely impossible. Supporting other routers is a non-goal as far as I'm concerned — the router is a large part of what SvelteKit is. So my inclination is to close this, unless there's another use case that we want to try and enable? |
I do think there are cases where you might want to use a different router as @pngwn frequently points out. And I don't think that SSR code splitting would necessarily be a blocker since not all adapters support it and it's an optional feature on those that do. That being said, this PR is out-of-date and I'm not tremendously motivated to update it since the Routify folks never did much with it |
This is needed if you want to load any
.svelte
file fromhandle
One potential usecase would be allowing you to use any other router with SvelteKit allowing you to leverage SvelteKit adapters, HMR, etc. without using our router. I'm sure there'd be other use cases as well.
I tried using this with Routify and it basically worked except that Routify doesn't seem to support SSR.
Even if we don't expose this yet, separating out
ComponentLoader
from the routing options might be a nice change.I have purposefully not documented this as I consider it an experimental API still. We can add it to the docs after we flesh it out.