AlexErrant
AlexErrant
Explore posts from servers
SSolidJS
Created by AlexErrant on 3/7/2023 in #support
`createServerData` with `fetch` is returning `undefined` in `createEffect`
Here's a minimal example.
import { Component, createEffect} from "solid-js";
import { useRouteData } from "solid-start";
import { createServerData$ } from "solid-start/server";

export function routeData() {
return {
myServerData: createServerData$(
async () => {
await fetch("http://example.com") // this is necessary to cause the issue
return "hi world"
}
),
}
}

const Stories: Component = () => {
const { myServerData } = useRouteData<typeof routeData>();
// console.log("outer", myServerData()) // uncomment this to "fix" the issue

createEffect(() => {
console.log("create effect", myServerData()) // this logs `undefined`
})

return (
<div>
</div>
)
};

export default Stories;
import { Component, createEffect} from "solid-js";
import { useRouteData } from "solid-start";
import { createServerData$ } from "solid-start/server";

export function routeData() {
return {
myServerData: createServerData$(
async () => {
await fetch("http://example.com") // this is necessary to cause the issue
return "hi world"
}
),
}
}

const Stories: Component = () => {
const { myServerData } = useRouteData<typeof routeData>();
// console.log("outer", myServerData()) // uncomment this to "fix" the issue

createEffect(() => {
console.log("create effect", myServerData()) // this logs `undefined`
})

return (
<div>
</div>
)
};

export default Stories;
Note that the fetch is required to cause the issue and that I can "fix" the issue by calling the signal in the outer scope. I'm on solid-start 0.2.23. Is this expected behavior?
13 replies