zimo
zimo
SSolidJS
Created by zimo on 8/14/2024 in #support
Cache server variable separately in db, server, front-end
This works well, but I don't want to keep defining isLockedLocal in all my components. I would have hoped I could create sort of a global variable that I could use. But defining it in a globalStore.ts and exporting it I get weird errors because of createAsync() being defined outside a route I guess. Also isLockedLocal doesn't update in realtime. I will have to refresh the website to see the updates. I would prefer it more if isLockedLocal worked more like a global signal. What's the best practice here?
3 replies
SSolidJS
Created by zimo on 8/14/2024 in #support
Cache server variable separately in db, server, front-end
I have done this so far: serverLock.ts:
import { getSettingServer, getUserSession, isAdmin, setSettingServer } from "./databse";

export let isDbLocked = true;

// Function to set the lock state, both in memory and the database
export async function setLockState(newState: boolean) {
"use server"
const session = await getUserSession();
if (!isAdmin(session))
return;

const updatedCorrectly = await setSettingServer("lockDb", newState.toString());
if (updatedCorrectly)
isDbLocked = newState;

console.log("isLocked is now " + isDbLocked);
return updatedCorrectly;
}

// Initialize the lock state from the database when the server starts
export async function initializeLockState() {
// "use server"
const dbValue = await getSettingServer("lockDb");
if (dbValue !== undefined) {
isDbLocked = dbValue === "true";
}
else {
await setSettingServer("lockDb", isDbLocked.toString())
}
}
import { getSettingServer, getUserSession, isAdmin, setSettingServer } from "./databse";

export let isDbLocked = true;

// Function to set the lock state, both in memory and the database
export async function setLockState(newState: boolean) {
"use server"
const session = await getUserSession();
if (!isAdmin(session))
return;

const updatedCorrectly = await setSettingServer("lockDb", newState.toString());
if (updatedCorrectly)
isDbLocked = newState;

console.log("isLocked is now " + isDbLocked);
return updatedCorrectly;
}

// Initialize the lock state from the database when the server starts
export async function initializeLockState() {
// "use server"
const dbValue = await getSettingServer("lockDb");
if (dbValue !== undefined) {
isDbLocked = dbValue === "true";
}
else {
await setSettingServer("lockDb", isDbLocked.toString())
}
}
Then I can use it like this in the frontend:
import { createAsync } from "@solidjs/router";
import "./MaintenanceMessage.css";
import { Show } from "solid-js";
import { isDbLocked } from "~/server/serverLock";

const MaintenanceMessage = () => {
const isLockedLocal = createAsync(async () => {
"use server"
return isDbLocked;
});

return <Show when={isLockedLocal()}>
<div class="info-box">[Site is under maintenance]
<span class="info-text">The site is in read-only mode. <br />Some functions like voting/submitting are temporarily disabled.</span>
</div>
</Show>;
};

export default MaintenanceMessage;
import { createAsync } from "@solidjs/router";
import "./MaintenanceMessage.css";
import { Show } from "solid-js";
import { isDbLocked } from "~/server/serverLock";

const MaintenanceMessage = () => {
const isLockedLocal = createAsync(async () => {
"use server"
return isDbLocked;
});

return <Show when={isLockedLocal()}>
<div class="info-box">[Site is under maintenance]
<span class="info-text">The site is in read-only mode. <br />Some functions like voting/submitting are temporarily disabled.</span>
</div>
</Show>;
};

export default MaintenanceMessage;
3 replies
SSolidJS
Created by zimo on 7/31/2024 in #support
Component with only <For /> in it removes all HTML children
That was a good idea, but I realized I needed my <MapCountry> components in a specific element in Mapbox-gl for the paning and zooming to work correctly.
5 replies
SSolidJS
Created by zimo on 7/31/2024 in #support
Component with only <For /> in it removes all HTML children
Goated solution! Thank you for introducing me to Portals :)
5 replies
SSolidJS
Created by zimo on 7/21/2024 in #support
Prisma integration example fails in build
yes hopefully soon :)
7 replies
SSolidJS
Created by zimo on 7/21/2024 in #support
Prisma integration example fails in build
Oh my God this is it. I tried changing the URL in an earlier attempt but I think it failed when I gave it a sham path, so I just assumed this was not the error. But it must have found the Schema but not the db file just like you said. It all makes sense now. Thank you as always Katja :)
7 replies
SSolidJS
Created by zimo on 7/21/2024 in #support
Prisma integration example fails in build
Thing is, I don't want to build like the comment I linked. I want to use SQLite and not Postgres and it had been working in the past. I have tried running that command without changing db type but it does nothing.
7 replies
SSolidJS
Created by zimo on 7/20/2024 in #support
Generic yet obscure Vinxi error when compiling
Solved :) Updated Vinxi from 0.3.10 -> 0.3.14 I had prior dependencies that prevented me from using newer versions
2 replies
SSolidJS
Created by zimo on 7/17/2024 in #support
Navigating through @solidjs/router doesn't load global app.css
I see. I use context very rarely and should looking into understanding it better and using it more often probably :) Thanks
25 replies
SSolidJS
Created by zimo on 7/17/2024 in #support
Navigating through @solidjs/router doesn't load global app.css
Okay thanks. I have generally defined a bunch of signals in their corresponding components, then exported them and checked them in other components. Example: NavBar.tsx defines and exports [navBarOpen, setNavBarOpen] so that I can close the navbar when another component prompts an alert for example. (akin to "compBProp" in my diagram) Another example is a global signal [isMobile, setIsMobile] which determines page layouts. (akin to "appProp" in my diagram) What would be a better way to define these signals? Use a global store in its own .ts file? Define all signals in a common .ts file? Are there any guidelines on patterns like this?
25 replies
SSolidJS
Created by zimo on 7/17/2024 in #support
Navigating through @solidjs/router doesn't load global app.css
Again, here is my comment on the GH issue: https://github.com/solidjs/solid-start/issues/1401#issuecomment-2233170499 I tried making an as minimal as possible project to demonstrate the problem: https://github.com/zimonitrome/solid_error_demo
25 replies
SSolidJS
Created by zimo on 7/17/2024 in #support
Navigating through @solidjs/router doesn't load global app.css
The yellow boxes in the image are signals. When either of the two signals are NOT imported, the css is loaded as expected. I.e. if "ref1 or "ref2" in the image is broken, the problem disappears. So maybe what happens is that index.tsx loads compB.tsx which loads app.tsx and all along the way the app.css is seen by Vinxi as being imported by index.tsx. Hence why it gets removed when navigating to otherpage.tsx.
25 replies
SSolidJS
Created by zimo on 7/17/2024 in #support
Navigating through @solidjs/router doesn't load global app.css
No description
25 replies
SSolidJS
Created by zimo on 7/17/2024 in #support
Navigating through @solidjs/router doesn't load global app.css
so my application works fine in prod, albeit with some overhead of duplicate links
25 replies
SSolidJS
Created by zimo on 7/17/2024 in #support
Navigating through @solidjs/router doesn't load global app.css
to clarify: the duplicate CSS links are still a problem in prod, but the missing css links are not
25 replies
SSolidJS
Created by zimo on 7/17/2024 in #support
Navigating through @solidjs/router doesn't load global app.css
As long as you and Nikhil are aware of the problem then I'm happy :) It appears to only be a problem in dev anyway. It's just an inconvenience when debugging and implementing routing behaviors.
25 replies
SSolidJS
Created by zimo on 7/17/2024 in #support
Navigating through @solidjs/router doesn't load global app.css
I'm not entirely sure it's related but both are unexpected behavior.
25 replies
SSolidJS
Created by zimo on 7/17/2024 in #support
Navigating through @solidjs/router doesn't load global app.css
maybe @ryansolid could reopen the issue
25 replies
SSolidJS
Created by zimo on 7/17/2024 in #support
Navigating through @solidjs/router doesn't load global app.css
Nice. I posted this even more simplified version of the problem here in the original issue thread: https://github.com/solidjs/solid-start/issues/1401#issuecomment-2233170499 Do you think this will be visible or should I create yet another issue?
25 replies
SSolidJS
Created by zimo on 7/17/2024 in #support
Navigating through @solidjs/router doesn't load global app.css
thank you so much 🙏 I was going a little crazy gonna try to comment on that PR/issue
25 replies