Skip to content

Commit

Permalink
Remove unnecessary if (isBrowser) check - effect only runs in browser
Browse files Browse the repository at this point in the history
  • Loading branch information
SeppahBaws committed May 16, 2024
1 parent 093cb01 commit b133543
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 36 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -290,15 +290,13 @@ describe('Svelte 5 runes', function () {
let value = $derived(_houdini_TestQuery);
$effect(() => {
if (isBrowser) {
_houdini_TestQuery.fetch({
variables: marshalInputs({
config: getCurrentConfig(),
artifact: _houdini_TestQuery.artifact,
input: {}
})
});
}
_houdini_TestQuery.fetch({
variables: marshalInputs({
config: getCurrentConfig(),
artifact: _houdini_TestQuery.artifact,
input: {}
})
});
});
`)
})
Expand Down Expand Up @@ -351,23 +349,21 @@ describe('Svelte 5 runes', function () {
const result = $derived(_houdini_TestQuery);
$effect(() => {
if (isBrowser) {
_houdini_TestQuery.fetch({
variables: marshalInputs({
config: getCurrentConfig(),
artifact: _houdini_TestQuery.artifact,
input: _TestQueryVariables.call(new RequestContext(), {
props: {
prop1: prop1,
prop2: prop2,
prop3: prop3,
prop4: prop4
}
})
_houdini_TestQuery.fetch({
variables: marshalInputs({
config: getCurrentConfig(),
artifact: _houdini_TestQuery.artifact,
input: _TestQueryVariables.call(new RequestContext(), {
props: {
prop1: prop1,
prop2: prop2,
prop3: prop3,
prop4: prop4
}
})
});
}
})
});
});
`)
})
Expand Down
14 changes: 3 additions & 11 deletions packages/houdini-svelte/src/plugin/transforms/componentQuery.ts
Original file line number Diff line number Diff line change
Expand Up @@ -224,10 +224,9 @@ export default async function QueryProcessor(config: Config, page: SvelteTransfo

/**
* In Runes mode, we need to generate:
* (the effect rune only runs in the browser, so we don't need to do an extra check)
* $effect(() => {
* if (isBrowser) {
* _houdini_<queryName>.fetch({...})
* }
* _houdini_<queryName>.fetch({...})
* })
*
* In legacy mode, we need to generate:
Expand All @@ -240,14 +239,7 @@ export default async function QueryProcessor(config: Config, page: SvelteTransfo
AST.callExpression(AST.identifier('$effect'), [
AST.arrowFunctionExpression(
[],
AST.blockStatement([
AST.ifStatement(
AST.identifier('isBrowser'),
AST.blockStatement([
AST.expressionStatement(queryLoadExpression),
])
),
])
AST.blockStatement([AST.expressionStatement(queryLoadExpression)])
),
])
),
Expand Down

0 comments on commit b133543

Please sign in to comment.