zenn-markdown-html 0.2.12-alpha.0 → 0.2.12-alpha.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -26,10 +26,22 @@ var _shiki = require("shiki");
26
26
  */
27
27
 
28
28
  /**
29
- * Shiki ハイライターのシングルトンインスタンス
30
- * getHighlighter() で初期化され、以降は再利用される
29
+ * Shiki ハイライターの初期化 Promise をキャッシュ
30
+ *
31
+ * 注: インスタンスではなく Promise をキャッシュすることで、
32
+ * Promise.all による並列処理時の競合状態を防ぐ。
33
+ *
34
+ * 問題のあるパターン:
35
+ * let instance = null;
36
+ * if (instance) return instance;
37
+ * instance = await createHighlighter(); // ← await 中に他の呼び出しが来る
38
+ *
39
+ * 正しいパターン:
40
+ * let promise = null;
41
+ * if (!promise) promise = createHighlighter(); // ← await しない
42
+ * return promise; // ← 同じ Promise を返す
31
43
  */
32
- let highlighterInstance = null;
44
+ let highlighterPromise = null;
33
45
  const SHIKI_THEME = 'github-dark';
34
46
 
35
47
  /**
@@ -37,16 +49,14 @@ const SHIKI_THEME = 'github-dark';
37
49
  * 最初は最低限のセットで初期化し、必要に応じて言語をロードする
38
50
  */
39
51
  async function getHighlighter() {
40
- if (highlighterInstance) {
41
- return highlighterInstance;
52
+ if (!highlighterPromise) {
53
+ // Promise をキャッシュ(await しない)
54
+ highlighterPromise = (0, _shiki.createHighlighter)({
55
+ themes: [SHIKI_THEME],
56
+ langs: []
57
+ });
42
58
  }
43
-
44
- // 最初は空の言語セットで初期化(高速)
45
- highlighterInstance = await (0, _shiki.createHighlighter)({
46
- themes: [SHIKI_THEME],
47
- langs: []
48
- });
49
- return highlighterInstance;
59
+ return highlighterPromise;
50
60
  }
51
61
 
52
62
  /**
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "zenn-markdown-html",
3
- "version": "0.2.12-alpha.0",
3
+ "version": "0.2.12-alpha.1",
4
4
  "license": "MIT",
5
5
  "description": "Convert markdown to zenn flavor html.",
6
6
  "main": "lib/index.js",
@@ -62,7 +62,7 @@
62
62
  "sanitize-html": "^2.17.0",
63
63
  "shiki": "^1.24.0"
64
64
  },
65
- "gitHead": "3d5f1d52c73b986b5a0ec911c7078d7a4822566a",
65
+ "gitHead": "1fb8da6f1e1ecb8c5dbef801efc152d7b94ae69f",
66
66
  "publishConfig": {
67
67
  "access": "public"
68
68
  }