S
SolidJS12mo ago
zeb

Empty event with useRequest()

I'm getting an empty event (no properties on the object) via useServerContext() even when isServer is true. Is that ever supposed to happen? I'm using the cloudflare pages adapter if that narrows it down.
3 Replies
zeb
zeb12mo ago
I have an incredibly basic component that's just trying to append some cache headers:
export function Cache({
cacheControl,
cacheTag,
etag,
expires,
lastModified,
}: CacheProps) {
const event = useRequest();

if (isServer) {
console.log(event);
cacheControl && event.responseHeaders.append("Cache-Control", cacheControl);
cacheTag && event.responseHeaders.append("Cache-Tag", cacheTag);
etag && event.responseHeaders.append("ETag", etag);
expires && event.responseHeaders.append("Expires", expires);
lastModified && event.responseHeaders.append("Last-Modified", lastModified);
}

// We don't want to actually render anything.
return null;
}
export function Cache({
cacheControl,
cacheTag,
etag,
expires,
lastModified,
}: CacheProps) {
const event = useRequest();

if (isServer) {
console.log(event);
cacheControl && event.responseHeaders.append("Cache-Control", cacheControl);
cacheTag && event.responseHeaders.append("Cache-Tag", cacheTag);
etag && event.responseHeaders.append("ETag", etag);
expires && event.responseHeaders.append("Expires", expires);
lastModified && event.responseHeaders.append("Last-Modified", lastModified);
}

// We don't want to actually render anything.
return null;
}
responseHeaders is always undefined and event seems to never have any properties
zeb
zeb12mo ago
Oddly enough the component on the left works but on the right doesn't. So I guess it's a bundler thing?
zeb
zeb12mo ago
Yeah when being imported from an outside package using pnpm link the useRequests get compiled into a useRequest and a useRequest$1 with the later one functioning Is there anything special I need to do to get the package on the right bundling correctly?
Want results from more Discord servers?
Add your server
More Posts
Example of using createWebSocketServer within an API endpoint with SSR: falseIs there a simple example of using createWebSocketServer within an API enpoint? Current `with-websocSolid Bootstrap Data TableHi Im looking for a custom solid-js data table solution. To minimize my workload, of course I beliHow to get `useParams` in the "root.tsx" in a server-rendered-page.Inside the `root.tsx` before any `FileRoutes` are resolved, how can we get the full path / the param[Solid-start]FileRoutes] is there a way of using two separate Routes folders in `root.tsx`E.g., my main content should be Client-Side rendered, but the headers should be server side renderedHow to call for server-side-data in the `root.tsx` of solid-start`Since I want to wrap my entire site in `<ClientOnly>` in the `root.tsx`, I can't use `useRouteData` Any tools for SolidJS that you wish you had?Hey everybody, My team and I working on an open source project with some restrictions; one of them bRouter Error when on a server with lazy loaded component on root pageWhen I deploy my website on a webserver and I load the "/" route I get an error in the browser consoRuntime Env vars in viteHey all, I'm trying to figure out a way to run environment variables *at runtime* rather than at comAwait for signal state?My website checks the login state upon initial load and a Resource on a page is failing to load becaResource from async generator?Hey everyone, brand new to SolidJS. I'm working with a library that uses an async generator to retu