-
-
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
Reserve config
export
#7845
Comments
Are there particular reasons for allowing other unknown exports? I feel like that would be a good idea. We're already reserving all |
I'm pretty use people use other exports to deduplicate some stuff, so I'm wary of adding a strict "nope" here. The alternative for this is configuration: For every feature that would be breaking, we create a config option which makes you opt in to the new export handling, and those are removed for version 2 at which point everyone has to migrate. |
Deduplicate what sort of stuff? Couldn't that be exported by another file, which is then imported (and/or re-exported) by |
I've definitely done this sort of thing in the past (and reused export function read(slug) {
return fs.readFileSync(`content/${slug}.md`, 'utf-8');
}
export function load({ params }) {
return {
html: marked(read(params.slug))
};
} It absolutely could be exported from a different file. I don't think there's ever a reason you'd need to export something custom from a route file. But it could be mildly cumbersome if you were (for example) exporting something purely for the sake of unit testing it. I am firmly in the Undecided camp. |
Yes, but not "mildly," IMO. For example, I have a wrapper that allows me to write and test action functions according to my own lights about export const signIn = async (event: RequestEvent): Promise<Redirect> => {
// blah blah blah
};
export const actions: Actions = {
default: wrapAction<SignInFormData>(signIn)
}; Disallowing this would either mean (a) making another file or (b) writing less concise, more convoluted functions/tests. I'd be happy to add an underscore to the exported wrapped function: |
Some advanced (and very useful) plugins like https://github.com/HoudiniGraphql/houdini also take advantage of exporting stuff there. Overall if feels unnecessarily restricting and will close the door to many potential ingenious plugins later on (which is sad considering plugins may become very important for svelte-kit at some point). |
Allowing underscore-prefixed exports per @cdcarson's suggestion would allow plugins/libraries to do whatever they needed though, right? If anything the existence of those sorts of integrations makes it much more important that we're able to distinguish between framework space and user space. Cc @AlecAivazis |
cc @jycouet |
In import type { MyPageQueryVariables as V } from './$houdini'
export const MyPageQueryVariables: V = (event) => {
return { id: event.params.id }
} In the background, houdini vite plugin generates something like: import { load_MyPageQuery } from '$houdini'
import type { PageLoad } from './$types'
export const load: PageLoad = async (event) => {
return load_MyPageQuery({ event, variables: { id: event.params.id } })
} Houdini users get to choose the syntax they want. It's just an example, we also provide other hooks like |
With |
Out of all of the proposed options, the That being said, I do kind of want to challenge if this is necessary at all. Like @jycouet and @gterras mentioned, Houdini adds a lot of special values to the salad of magic names in
Is this because of a technical reason or a human one (documentation, education, etc)? While I can't speak with 100% certainty, I haven't heard of anyone being confused by this mixing. If anything, i think it creates a rather nice narrative where users are free to mix and match Kit and Houdini without juggling multiple files or different conventions. In some sense, making sure we add features in a kit-compatible way is our job as authors of a meta-layer. A concrete example of this is when we added the "houdini_" prefix to
The goal for us is to dramatically reduce the amount of boilerplate that a user has to maintain by assuming as much as possible. If the solution is to move all of that out of the +page file and into a houdini-specific file, we'll have to come up with a new special prefix which feels like an unnecessary complication. For some additional context, we are using the |
I'm not familiar with Houdini's innards, but from a quick glance it sounds like you're essentially rewriting the |
So there are a few things at play here. When I first started building the vite plugin, I wanted to avoid the static analysis by importing the file from within the Regardless of the plugin's current implementation, our magic values need to be exported because the types that we generate to fill the same role was the edit3: consolidated, reworded, and removed a lot of context. i want to avoid this becoming a houdini-specific conversation since I think the original issue is very general and focused on adapters which have a very different set of goals and constraints. I'd love to go deeper into the notion of a SvelteKit plugin and what it should be allowed to do but I think this is the wrong place for that since it's definitely a post-1.0 thing. Maybe #6708 is more appropriate? |
Thanks — I'm still unclear on whether entry points have the custom exports after the Houdini transform is done with them though? |
Yea they do but the primary reason is laziness/simplicity . However, once that issue is fixed, I think removing the custom exports would create a problem since the plugin wouldn't be able to import the file and see if anything special was exported |
But doesn't the plugin do its magic before the file is seen by SvelteKit? So the plugin could (all before the file is seen by SvelteKit)
The typings are separate, at least on our side they work through simple static analysis and doing some simple AST transforms, resulting in some generated types - no validation of forbidden exports there. |
Yes that's how things work now and likely how things would have to stay if exports were removed. Like I said, the hurdle I mentioned only pops up once vitejs/vite#6810 is addressed since it muddles the processing order a bit: a plugin that generates code based on custom exports might want to call In general, I'm not a huge fan of going against the grain when it comes to constraints imposed by Kit. I think I'd rather require users to add the I still think this is part of a larger conversation about what the development experience for a SvelteKit plugin is like. The code that performs the static analysis to look at exports in
Clearly these aren't that bad to support or work around but it does leave me with a feeling that there's an opportunity for a smoother experience for developers looking to build Kit-specific plugins. These plugins have common needs which are out of scope for treating it like a generic vite plugin, like looking at the exported values of |
Just to reiterate - I dont think this conversation is super relevant to the original issue. Nor do I expect this to be resolved before 1.0 can get released. I understand the want to group as many breaking changes as possible before 1.0 and i would feel very bad if this conversation was blocking the release. To me, it seems like the |
Describe the problem
We've alluded to a vague plan to support route-level deployment config in the future — something like this...
...where
config
is a freeform (but serializable) object that gets passed to adapters so that they can use it to customise the deployment.At the moment, you can export anything from a
+(layout|page)(.server)?.js
file. This means that adding a new known export would be a breaking change, as someone might already be doingexport const config = {...}
for some other reason.Describe the proposed solution
Reserve the
config
name, i.e. throw an error if a route file exports a binding calledconfig
.Alternatives considered
Prevent any unknown exports. This is safer, but might feel unduly restrictive.
Importance
would make my life easier
Additional Information
No response
The text was updated successfully, but these errors were encountered: