HMR causes multiple instances
まだ誰も着手していません。
評価
- 難易度
- 4/5
- 見積もり時間
- 3〜5日
- 初心者へのやさしさ
- 52/100
- issue の種類
- バグ
- 明瞭さ
- おおむね明確
- 活発さ
- 活発
- 技術スタック
- javascript, next.js, node.js
調査の方向性
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.
索引モデルが issue の本文から書いたものです。
説明
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.
- 主要言語
- JavaScript
- スター
- 22.6k
- フォーク
- 965
- 平均マージ
- 45分
- マージ済み PR(30日)
- 2
環境構築
- Dockerfile・Docker Compose ファイルなし
- プルリクエストのテンプレートなし
- コントリビューションガイドを読む
はじめの一歩
- issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
- 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
- リポジトリをフォークし、ブランチを切って変更します。
- issue 番号を参照したプルリクエストを送ります。
typicode/lowdb のほかの issue
-
Documentation pleaseオープン
難易度 2/5 1〜3時間 初心者へのやさしさ 68/100
似ている issue
-
from-review tech-debt testing
難易度 2/5 1〜3時間 初心者へのやさしさ 82/100
blamechris/chroxy#9520 ·
メンテナーはふだん 1 日以内に返信
-
bug
難易度 2/5 1〜3時間 初心者へのやさしさ 78/100
freelawproject/litigant-portal#1307 ·
メンテナーはふだん 2 日以内に返信
-
Java Edition Tests
難易度 2/5 1〜3時間 初心者へのやさしさ 72/100
JSPrismarine/JSPrismarine#4178 · コメント 1 件 · リアクション 1 件 ·
メンテナーはふだん 1 日以内に返信
-
難易度 2/5 1〜3時間 初心者へのやさしさ 76/100
Trac-Systems/main_settlement_bus#1278 ·
メンテナーはふだん 1 日以内に返信
-
documentation good first issue help wanted
難易度 2/5 1〜3時間 初心者へのやさしさ 76/100
apidly-ltd/apidly-mcp#5 ·