S
SolidJS2y 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
zebOP2y 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
zebOP2y ago
Oddly enough the component on the left works but on the right doesn't. So I guess it's a bundler thing?
zeb
zebOP2y 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