Skip to content
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

Wrong variable function input for inline component queries #421

Closed
fehnomenal opened this issue Jul 17, 2022 · 6 comments · Fixed by #423
Closed

Wrong variable function input for inline component queries #421

fehnomenal opened this issue Jul 17, 2022 · 6 comments · Fixed by #423
Labels
Bug Something isn't working like it should

Comments

@fehnomenal
Copy link
Contributor

I wrote about this already here: #366 (comment) but now the problem resurfaced while trying to upgrade another project to the new store API.

Basically the problem is that the variable function only gets two values when being executed in the client, namely props and session:

AST.callExpression(
AST.memberExpression(
AST.identifier(queryInputFunction(name)),
AST.identifier('call')
),
[
contextIdentifier,
AST.objectExpression([
AST.objectProperty(
AST.identifier('props'),
// pass every prop explicitly
AST.objectExpression(
props.map((prop) =>
AST.objectProperty(
AST.identifier(prop),
AST.identifier(prop)
)
)
)
),
AST.objectProperty(
AST.identifier('session'),
AST.memberExpression(
contextIdentifier,
AST.identifier('session')
)
),
]),
]
)

My old code is using stuff via page but this is obviously no longer working.

Directly using $page.stuff... does not work because "Cannot reference store value inside <script context="module">".

Route ...Variable functions get a LoadEvent passed. Can we try to pass component ...Variable functions a trimmed LoadEvent? Something like:

type TrimmedLoadEvent = {
	params: Record<string, string>;
	props: Record<string, string>;
	routeId: string | null;
	session: App.Session;
	stuff: Partial<App.Stuff>;
	url: URL;
}
@fehnomenal
Copy link
Contributor Author

Btw: my current workaround is by defining the query in a gql file and calling via $: browser && GQL_...fetch({ variables: { foo: $page.stuff... } })

@jycouet
Copy link
Contributor

jycouet commented Jul 17, 2022

Thanks for reporting this @fehnomenal
Good workaround going a bit more manual while this is not supported in the preprocessor yet.

Most of TrimmedLoadEvent is already in place with getHoudiniContext().
Now, "just" need to support all items and push them to the preprocessor variables function.

How urgent do you need it in preprocessor? Do you want to give it a shot?

@AlecAivazis AlecAivazis added the Bug Something isn't working like it should label Jul 17, 2022
@AlecAivazis
Copy link
Collaborator

Ah crap! I totally forgot to verify that we fixed your stuff issue before we merged that - so sorry! I'll try to find some time this week to address this is no one else gets to it.

Also, just a heads up it looks like $page.stuff might be removed at some point: sveltejs/kit#4911

@fehnomenal
Copy link
Contributor Author

How urgent do you need it in preprocessor? Do you want to give it a shot?

Well, as the project is just for a side business and not my day job and there is a workaround available it is not on the top of my priority list.

When I get a few minutes I will tackle it.

@fehnomenal
Copy link
Contributor Author

Also, just a heads up it looks like $page.stuff might be removed at some point

Wow, thanks for mentioning that. We'll see if there and what will be a replacement.

Maybe it's time for me to fully switch to stores and ditch the inline queries

@AlecAivazis
Copy link
Collaborator

I was able to sneak in some time tonight so I put #423 together. Hopefully that addresses your issue

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug Something isn't working like it should
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants