HMR causes multiple instances
Nadie ha tomado este issue todavía.
Evaluación
- Dificultad
- 4/5
- Tiempo estimado
- 3-5 días
- Aptitud para principiantes
- 52/100
- Tipo de issue
- Error
- Claridad
- Bastante claro
- Estado de actividad
- Activo
- Stack tecnológico
- javascript, next.js, node.js
Línea de trabajo
Start by reading the open() usage in the issue and how lowdb manages database instances and their lifecycle. Reproduce the duplicate-open error in a Next.js server component with HMR, then inspect the relevant instance and close APIs. Done means a supported pattern prevents multiple instances writing the same file during HMR and is documented clearly.
Escrito por el modelo de indexación a partir del texto del issue.
Descripción
In a Next.js application changing a file causes a HMR update to occur. This is pretty standard practice, but LowDB is not properly designed to handle it.
The error:
[browser] Uncaught Error: lowdb: media.jsonl is already open in this process. Call open() once and share the returned db; two instances writing the same file would diverge.
And before you panick: it actually runs on the server. I don't know why it says [browser] there, but it does, so I thought it might be worth including. The lib is called upon from a server component.
The code:
import { open, DeepReadonly } from "lowdb";
import { Data } from "./type"; // actual type doesn't matter
const init = { media: [] };
const db = open<Data>("data/media.jsonl", init);
export const getData = (): DeepReadonly<Data> => {
return db.data;
}
Where should I put close()?
Not at the and of the file - that would immedaitely close the db after opening. Not at the end of the getData function. That would close the db after the first retrieval, and then stop working because the db is not open. I cannot wrap this in a using block - you can't export from such a block, which is understandable.
PS, I'm totally guessing that this is how one creates a lib for db handling stuff. There's no proper documentation on how to do this, so I have to resort to asking questions that probably look dumb.
- Lenguaje dominante
- JavaScript
- Estrellas
- 22.6k
- Forks
- 965
- Merge medio
- 45 min
- PR fusionados (30 d)
- 2
Preparar el entorno
- Sin Dockerfile ni archivo de Docker Compose
- Sin plantilla de pull request
- Leer la guía de contribución
Primeros pasos
- Lee el issue completo y luego la guía de contribución del proyecto.
- Comenta en el issue que vas a ocuparte — evita que dos personas hagan lo mismo.
- Haz un fork del repositorio y trabaja en una rama.
- Abre un pull request que haga referencia al número del issue.
Más de typicode/lowdb
-
Documentation pleaseAbierto
Dificultad 2/5 1-3 horas Aptitud para principiantes 68/100
Todos los issues de typicode/lowdb
Issues similares
-
from-review tech-debt testing
Dificultad 2/5 1-3 horas Aptitud para principiantes 82/100
blamechris/chroxy#9520 ·
Los mantenedores suelen responder en 1 día
-
bug
Dificultad 2/5 1-3 horas Aptitud para principiantes 78/100
freelawproject/litigant-portal#1307 ·
Los mantenedores suelen responder en 2 días
-
Java Edition Tests
Dificultad 2/5 1-3 horas Aptitud para principiantes 72/100
JSPrismarine/JSPrismarine#4178 · 1 comentario · 1 reacción ·
Los mantenedores suelen responder en 1 día
-
Dificultad 2/5 1-3 horas Aptitud para principiantes 76/100
Trac-Systems/main_settlement_bus#1278 ·
Los mantenedores suelen responder en 1 día
-
documentation good first issue help wanted
Dificultad 2/5 1-3 horas Aptitud para principiantes 76/100
apidly-ltd/apidly-mcp#5 ·