alrightsure
alrightsure
Explore posts from servers
SSolidJS
Created by alrightsure on 9/5/2024 in #support
Top level "use server" doesn't seem to work
Hey all, I've noticed that I put "use server" at the top of the file, it doesn't seem to actually treat the functions in the file as server functions, and the actions don't work as expected. I wanted to ask here before filing an issue, as I feel like maybe I am misunderstanding. For example, this seems to work:
import { db } from "./db";
import { action, cache, revalidate } from "@solidjs/router";

export const getMessages = cache(async () => {
"use server";

const messages = await db.messages.findMany();
return messages;

}, "messages");

export const sendMessage = action(async ({ text }: { text: string }) => {
"use server";

await db.messages.create({
data: { text }
});

revalidate(getMessages.keyFor());
});
import { db } from "./db";
import { action, cache, revalidate } from "@solidjs/router";

export const getMessages = cache(async () => {
"use server";

const messages = await db.messages.findMany();
return messages;

}, "messages");

export const sendMessage = action(async ({ text }: { text: string }) => {
"use server";

await db.messages.create({
data: { text }
});

revalidate(getMessages.keyFor());
});
However, this throws an error when I try to call these functions:
"use server";

import { db } from "./db";
import { action, cache, revalidate } from "@solidjs/router";

export const getMessages = cache(async () => {
const messages = await db.messages.findMany();
return messages;

}, "messages");

export const sendMessage = action(async ({ text }: { text: string }) => {
await db.messages.create({
data: { text }
});

revalidate(getMessages.keyFor());
});
"use server";

import { db } from "./db";
import { action, cache, revalidate } from "@solidjs/router";

export const getMessages = cache(async () => {
const messages = await db.messages.findMany();
return messages;

}, "messages");

export const sendMessage = action(async ({ text }: { text: string }) => {
await db.messages.create({
data: { text }
});

revalidate(getMessages.keyFor());
});
Is this intended behavior?
6 replies
SSolidJS
Created by alrightsure on 5/18/2023 in #support
useRouteData empty on HMR
I'm just curious about the expected behavior of useRouteData in Solid Start. It seems to return an empty response after HMR, but only in certain situations. I created two identical pages with different route data functions. One pulls from the Pokemon API and another accesses my firestore instance:
export const routeData = () => {
return createServerData$(async () => {
const resp = await fetch("https://pokeapi.co/api/v2/pokemon/ditto");
return await resp.json();
});
};
export const routeData = () => {
return createServerData$(async () => {
const resp = await fetch("https://pokeapi.co/api/v2/pokemon/ditto");
return await resp.json();
});
};
export const routeData = () => {
return createServerData$(async () => {
const exercisesSnapshot = await db.exercises.get();
return exercisesSnapshot.docs.map(doc => ({ id: doc.id, ...doc.data() }));
});
};
export const routeData = () => {
return createServerData$(async () => {
const exercisesSnapshot = await db.exercises.get();
return exercisesSnapshot.docs.map(doc => ({ id: doc.id, ...doc.data() }));
});
};
The Pokemon page seems to persist data through HMRs, however, my route data from firestore seems to be empty after an HMR. Does anyone have any insight into this?
3 replies
SSolidJS
Created by alrightsure on 1/27/2023 in #support
Calling database with server actions in Solid Start
Hey all, I have a question more about best practices than anything. In the Solid Start docs, under the Server Actions heading, it says the following:
Or even connecting directly to a database. (Take caution, opinions on if this is a good idea are mixed. You should consider separating your backend and frontend).
Or even connecting directly to a database. (Take caution, opinions on if this is a good idea are mixed. You should consider separating your backend and frontend).
My question is why this may be considered a bad idea, especially when it's not frowned upon in createServerData$.
8 replies