zimo
Cache server variable separately in db, server, front-end
So I have the idea to be able to "lock" my database for maintenance I sometimes do offline.
My idea is thus to have a "locked" setting in a persistent settings table in my database. On startup, the server should read this setting and set a server-side variable based on it, let's called it
isDbLocked
.
I would then like the front end to be able to read this server-side variable to disable some UI elements.
An admin should then be able to change this variable through the UI. Which in turn tries to update the database. If successful, it updates the server-side variable, and thus the front end too (maybe makes a new explicit request here to update it).
My question is how to do this in practice in SolidStart? I tried something like just having a .ts
file with a isDbLocked
variable, then an init function that queries the db on server init. But I can't just import and use isDbLocked
probably... I would need to fetch it from the server? Should I createResource
or "use server"
?
Also is this overly complicated? Should I just always make requests that always read the db and returns the setting instead of having an intermediate server-side variable? My idea was to reduce requests to the DB since we always know the value of isDbLocked
. It's only ever changed when an admin changes it.3 replies
Component with only <For /> in it removes all HTML children
I have this set up:
Where the outer div is used as a reference to attach a Mapbox-gl canvas element, along with some more HTML elements. But I also fill it with some components of my own "MapCountry".
My problem is that when mainStore.countries is an empty list, Solid removes all children of my outer div, including the elements created by Mapbox-gl.
My current work-around is to add a dummy element to the outer div:
Is this the best solution? Could I prevent solid from removing all items?
5 replies
Prisma integration example fails in build
Could someone help me try to reproduce a bug I get in the official
npm init solid@latest
?
1. npm init solid@latest
2. Select the following options: Solid-Start: Yes, TypeScript: Yes, template: "with-prisma"
3. cd into project folder
4. npm install
5. npx prisma generate
6. npx prisma migrate dev
7. npm run dev
8. Open "localhost:3000". Interact with the site. Register a user, login, logout. Observe correct behavior.
9. npm run build
10. node .output/server/index.mjs
11. Open "localhost:3000". Interact with the site. Register a user, login, logout. Observe it's impossible. Error: Invalid
prisma.user.findUnique() invocation: The table
main.User does not exist in the current database.
I wrote an issue on the Prisma repo here: https://github.com/prisma/prisma/issues/24845
but I don't see other people with this error so it might be something in the Solid/Vinxi ecosystem.7 replies
"Cannot find module" for image files
Whenever I do something like I get a TS error of . Same goes for
.module.css
files, but .css
imports correctly.
I tried adding a declarations.d.ts
file:
Which I import in tsconfig, restart the TS server but the error persists:
It all compiles fine and the files are found, it's just an annoying TS error.
Any idea why this happens and how to fix this?1 replies
css loads slowly (lazily?) causing ugly page for a few frames
I just tried upgrading to latest version of SolidStart and noticed this.
Others seem to have noticed similar things in the past:
https://discord.com/channels/722131463138705510/910635844119982080/1233478382482620532
https://github.com/solidjs/solid-start/pull/1423 (this issue have nice pictures demonstrating what's happening)
That PR seems to be merged but it still happens to me.
I did not experience this in some beta versions where only Vite was used. So I suspect it might be a Vinxi problem.
Sample project for what I'm doing:
https://github.com/zimonitrome/SolidStart-Prisma-AuthJS-example
5 replies
"[error] UnknownAction" on getSession() in AuthJS
Hello, I have tried to follow the example here on using @solid-mediakit/auth: https://www.npmjs.com/package/@solid-mediakit/auth#server-side
I have implemented it as suggested but I am having trouble using
getSession()
. In previous versions I have used it in server-side db methods like this:
I have tried upgrading to something like:
And this is just called in a button onClick()
method on my frontend:
But the problem is that I get the following fairly generic error:
6 replies
Delete key in store
How do I delete a key in a store? My store is typed so I can't simply set the value to undefined.
Will I have to use the mutate helper, whatever it's called?
I'm used to changing keys in a store by just doing
setMyStore("my_key", value);
3 replies
Failed to execute 'replaceChild' on 'Node': The node to be replaced is not a child of this node.
I have a store:
of this type:
I'm trying to render only part of these countries, or rather their sprites. I filter them out and render them like this:
In short you can toggle between different
mapSkin()
and different characters()
, both of which currently have two settings.
It works OK when you go from no characters selected to a few selected, or when you seemingly replace all the sprites, but as soon as the resulting list expands or contracts I get the omnious error:
I have had this error for a few weeks now. Am I using stores incorrectly?7 replies
Mutate createServerData$ resource
I have a route component that renders countries:
I want to update countries() locally when pressing a button (and also on the db but I think I know how) and re-render the component. How would I go about doing this?
Something like this, but getting and setting the resource on the server as well
https://playground.solidjs.com/anonymous/fa0e93a0-5c83-44cc-913b-2801d96e1363
2 replies
Joining SolidJS Vite app with a rest api as single app
Hello, I'm building a simple front end with the default SolidJS+Vite template. I call this the client. The client need to call some things from a rest API server, so I currently have a second Node app running. Let's call this "server". The server uses Express to do some simple file management.
This is all fine and well. When I'm building for production I first build the client into /dist. I then move the /dist folder into the server and build the server into the final /dist for production.
This works, but I think it's a little ugly. Preferably I would want to have one single Node project with a single package.json, but that still has hot reloading.
How is this normally done?
2 replies