@quark-fw/plugin-react 0.1.17 → 0.1.18
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.
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@quark-fw/plugin-react",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.18",
|
|
4
4
|
"main": "src/index.ts",
|
|
5
5
|
"types": "src/index.ts",
|
|
6
6
|
"type": "module",
|
|
@@ -22,8 +22,8 @@
|
|
|
22
22
|
"access": "public"
|
|
23
23
|
},
|
|
24
24
|
"dependencies": {
|
|
25
|
-
"@quark-fw/atom": "0.1.
|
|
26
|
-
"@quark-fw/plugin": "0.1.
|
|
25
|
+
"@quark-fw/atom": "0.1.18",
|
|
26
|
+
"@quark-fw/plugin": "0.1.18",
|
|
27
27
|
"@trpc/client": "^11.0.0",
|
|
28
28
|
"@types/react-dom": "^19.2.3",
|
|
29
29
|
"express": "^5.2.1",
|
|
@@ -36,8 +36,8 @@
|
|
|
36
36
|
"@mantine/dates": "^9.0.0",
|
|
37
37
|
"@mantine/modals": "^9.0.0",
|
|
38
38
|
"@mantine/notifications": "^9.0.0",
|
|
39
|
-
"@quark-fw/core": "0.1.
|
|
40
|
-
"@quark-fw/store": "0.1.
|
|
39
|
+
"@quark-fw/core": "0.1.18",
|
|
40
|
+
"@quark-fw/store": "0.1.18",
|
|
41
41
|
"@vitejs/plugin-react": "^5.1.0",
|
|
42
42
|
"react": "^19.2.4",
|
|
43
43
|
"react-dom": "^19.2.4",
|
|
@@ -3,34 +3,51 @@ import type { Response } from "express";
|
|
|
3
3
|
import { UglyModule } from "../Router/UglyModule.js";
|
|
4
4
|
|
|
5
5
|
/**
|
|
6
|
-
* Пишет в ответ preload-теги
|
|
7
|
-
*
|
|
6
|
+
* Пишет в ответ preload-теги для модулей страницы, которые регистрирует
|
|
7
|
+
* роутер по мере рендера.
|
|
8
|
+
*
|
|
9
|
+
* modulepreload — только на чанк самого модуля и его прямые импорты: этого
|
|
10
|
+
* хватает, чтобы гидрация не ждала лишний хоп сети. Раньше обход шёл по
|
|
11
|
+
* всему графу импортов, и главная страница bina получала ~30 preload-ов на
|
|
12
|
+
* ~200 KB gzip, большую часть которых первый экран не исполнял. CSS, напротив,
|
|
13
|
+
* собирается по всему графу: стили вложенных чанков нужны к первому кадру,
|
|
14
|
+
* иначе разметка мигает без оформления. Каждый тег — один раз.
|
|
8
15
|
*/
|
|
9
16
|
export function createPreloadTagWriter(manifest: Manifest, res: Response) {
|
|
10
|
-
const
|
|
11
|
-
const written: Record<string, boolean> = {};
|
|
17
|
+
const written = new Set<string>();
|
|
12
18
|
|
|
13
|
-
const
|
|
19
|
+
const writeOnce = (id: string, tag: string) => {
|
|
20
|
+
if (written.has(id)) return;
|
|
21
|
+
written.add(id);
|
|
22
|
+
res.write(tag);
|
|
23
|
+
};
|
|
24
|
+
|
|
25
|
+
const writeCss = (link: string, seen = new Set<string>()): void => {
|
|
26
|
+
if (seen.has(link)) return;
|
|
27
|
+
seen.add(link);
|
|
14
28
|
const chunk = manifest[link];
|
|
15
|
-
if (chunk
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
if (!written[cssFile]) {
|
|
21
|
-
written[cssFile] = true;
|
|
22
|
-
res.write(`<link rel="stylesheet" href="/${cssFile}"/>`);
|
|
23
|
-
}
|
|
24
|
-
});
|
|
25
|
-
(chunk.imports ?? []).map((childLink) => extractTags(childLink));
|
|
26
|
-
}
|
|
29
|
+
if (!chunk) return;
|
|
30
|
+
(chunk.css ?? []).forEach((cssFile) =>
|
|
31
|
+
writeOnce(cssFile, `<link rel="stylesheet" href="/${cssFile}"/>`),
|
|
32
|
+
);
|
|
33
|
+
(chunk.imports ?? []).forEach((child) => writeCss(child, seen));
|
|
27
34
|
};
|
|
28
35
|
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
36
|
+
const writeModule = (link: string) => {
|
|
37
|
+
const chunk = manifest[link];
|
|
38
|
+
if (!chunk || chunk.name === "entry-client") return;
|
|
39
|
+
writeOnce(
|
|
40
|
+
chunk.file,
|
|
41
|
+
`<link rel="modulepreload" as="script" crossorigin href="/${chunk.file}">`,
|
|
42
|
+
);
|
|
43
|
+
};
|
|
32
44
|
|
|
33
|
-
|
|
34
|
-
|
|
45
|
+
return function registerModule(uglyModule: UglyModule) {
|
|
46
|
+
const link = uglyModule.modulePath.substring(1);
|
|
47
|
+
const chunk = manifest[link];
|
|
48
|
+
if (!chunk || chunk.name === "entry-client") return;
|
|
49
|
+
writeModule(link);
|
|
50
|
+
(chunk.imports ?? []).forEach(writeModule);
|
|
51
|
+
writeCss(link);
|
|
35
52
|
};
|
|
36
53
|
}
|