gatsby-matrix-theme 53.23.0 → 53.24.0
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/CHANGELOG.md +10 -0
- package/gatsby-node.js +4 -1
- package/gatsby-ssr.js +92 -0
- package/package.json +1 -1
- package/storybook/public/project.json +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -1,3 +1,13 @@
|
|
|
1
|
+
# [53.24.0](https://gitlab.com/g2m-gentoo/team-floyd/themes/matrix-theme/compare/v53.23.0...v53.24.0) (2026-07-02)
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
* Merge branch 'critical-css-ssr' into 'master' ([5115877](https://gitlab.com/g2m-gentoo/team-floyd/themes/matrix-theme/commit/511587745fa68b230b04f579251690bb8434e2fe))
|
|
5
|
+
|
|
6
|
+
|
|
7
|
+
### Features
|
|
8
|
+
|
|
9
|
+
* inject render-blocking module css on ssr routes ([aa36c7c](https://gitlab.com/g2m-gentoo/team-floyd/themes/matrix-theme/commit/aa36c7c57be4f6eba6981cb1c1f55462eacbf871))
|
|
10
|
+
|
|
1
11
|
# [53.23.0](https://gitlab.com/g2m-gentoo/team-floyd/themes/matrix-theme/compare/v53.22.4...v53.23.0) (2026-06-29)
|
|
2
12
|
|
|
3
13
|
|
package/gatsby-node.js
CHANGED
|
@@ -4,7 +4,10 @@
|
|
|
4
4
|
* Critical-CSS split (default OFF; enable per-site via options.criticalCss.enabled):
|
|
5
5
|
* 1. onCreateWebpackConfig — split CSS so only initial-chunk CSS stays inlined; lazy-module CSS
|
|
6
6
|
* goes to separate cacheable chunks.
|
|
7
|
-
* 2. onPostBuild — make each page's own chunks render-blocking (no async => no FOUC/CLS).
|
|
7
|
+
* 2. onPostBuild — make each STATIC page's own chunks render-blocking (no async => no FOUC/CLS).
|
|
8
|
+
*
|
|
9
|
+
* SSR routes (no static HTML; listed in options.criticalCss.skipRoutes) are handled by the SSR
|
|
10
|
+
* counterpart in ./gatsby-ssr.js, which injects the full module CSS render-blocking at request time.
|
|
8
11
|
*
|
|
9
12
|
* All hooks are guarded so a failure degrades gracefully and never breaks a consumer build.
|
|
10
13
|
*/
|
package/gatsby-ssr.js
ADDED
|
@@ -0,0 +1,92 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* gatsby-matrix-theme — SSR-side half of the critical-CSS split (default OFF; enabled per-site via
|
|
3
|
+
* options.criticalCss.enabled).
|
|
4
|
+
*
|
|
5
|
+
* The split (see gatsby-node.js) moves lazy-module CSS into async chunks. On STATIC pages,
|
|
6
|
+
* `onPostBuild` re-links the chunks each page needs render-blocking by rewriting the emitted HTML.
|
|
7
|
+
* SSR routes (app-ssr.js + getServerData, e.g. the search page `/s`) have no static HTML on disk,
|
|
8
|
+
* so `onPostBuild` cannot touch them — it explicitly `skipRoutes` them — and their module CSS would
|
|
9
|
+
* otherwise load async at hydration => FOUC/CLS.
|
|
10
|
+
*
|
|
11
|
+
* This hook is the SSR counterpart: for exactly the `skipRoutes` (the dynamic/SSR routes) it injects
|
|
12
|
+
* every module CSS chunk render-blocking at request time, restoring the pre-split "full CSS at first
|
|
13
|
+
* paint" behaviour. That is precisely what `skipRoutes` documents — "route prefixes to leave with
|
|
14
|
+
* default (full) inlining" — so one config list drives both halves of the feature:
|
|
15
|
+
* - onPostBuild -> static pages: detect + render-block per page
|
|
16
|
+
* - onRenderBody -> skipRoutes (SSR) pages: render-block the full module set
|
|
17
|
+
*
|
|
18
|
+
* Matches on the first path segment, so `/s` and `/preview` are covered without touching static
|
|
19
|
+
* pages. (SSR templates that live at arbitrary slugs — settings.app_ssr: event/tournament/… — are
|
|
20
|
+
* NOT segment-addressable; covering those needs a build-emitted SSR-path manifest, a later change.)
|
|
21
|
+
*
|
|
22
|
+
* Fully guarded — a failure degrades to split-only (no worse than before) and never breaks SSR.
|
|
23
|
+
*/
|
|
24
|
+
|
|
25
|
+
const fs = require('fs');
|
|
26
|
+
const path = require('path');
|
|
27
|
+
const React = require('react');
|
|
28
|
+
const { resolveConfig } = require('./critical-css/config');
|
|
29
|
+
|
|
30
|
+
// module chunks = every emitted stylesheet except the base (`styles.*`) and route shells
|
|
31
|
+
// (`component---*`), which Gatsby already inlines render-blocking for the matched route.
|
|
32
|
+
const isModuleChunk = (f) =>
|
|
33
|
+
f.endsWith('.css') && !/^styles\./.test(f) && !/^component---/.test(f);
|
|
34
|
+
|
|
35
|
+
let cachedLinks; // built once per server process (public/ is immutable for a given build)
|
|
36
|
+
|
|
37
|
+
// Resolve the consumer site's build output dir at request time (cwd is the site root under
|
|
38
|
+
// `gatsby serve` / gatsby-plugin-fastify). chunk-map.json marks a real Gatsby public/ dir.
|
|
39
|
+
function resolvePublicDir() {
|
|
40
|
+
const candidates = [path.join(process.cwd(), 'public'), path.join(__dirname, 'public')];
|
|
41
|
+
for (const dir of candidates) {
|
|
42
|
+
try {
|
|
43
|
+
if (fs.existsSync(path.join(dir, 'chunk-map.json'))) return dir;
|
|
44
|
+
} catch (e) {
|
|
45
|
+
/* try next */
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
return null;
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
function getModuleCssLinks() {
|
|
52
|
+
// only cache a non-empty success; retry on failure (dir may not be resolvable on an early call)
|
|
53
|
+
if (cachedLinks && cachedLinks.length) return cachedLinks;
|
|
54
|
+
try {
|
|
55
|
+
const dir = resolvePublicDir();
|
|
56
|
+
if (!dir) return [];
|
|
57
|
+
const files = fs.readdirSync(dir).filter(isModuleChunk);
|
|
58
|
+
cachedLinks = files.map((f) =>
|
|
59
|
+
React.createElement('link', {
|
|
60
|
+
key: f,
|
|
61
|
+
rel: 'stylesheet',
|
|
62
|
+
href: `/${f}`,
|
|
63
|
+
'data-crit-ssr': f,
|
|
64
|
+
})
|
|
65
|
+
);
|
|
66
|
+
return cachedLinks;
|
|
67
|
+
} catch (e) {
|
|
68
|
+
return [];
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
function firstSegment(pathname) {
|
|
73
|
+
return (
|
|
74
|
+
String(pathname || '')
|
|
75
|
+
.split('?')[0]
|
|
76
|
+
.split('/')
|
|
77
|
+
.filter(Boolean)[0] || ''
|
|
78
|
+
);
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
exports.onRenderBody = ({ setHeadComponents, pathname }, pluginOptions) => {
|
|
82
|
+
try {
|
|
83
|
+
const cfg = resolveConfig(pluginOptions);
|
|
84
|
+
if (!cfg.enabled) return;
|
|
85
|
+
if (!cfg.skipRoutes.includes(firstSegment(pathname))) return;
|
|
86
|
+
|
|
87
|
+
const links = getModuleCssLinks();
|
|
88
|
+
if (links.length) setHeadComponents(links);
|
|
89
|
+
} catch (e) {
|
|
90
|
+
/* never break SSR over a CSS optimisation */
|
|
91
|
+
}
|
|
92
|
+
};
|
package/package.json
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"generatedAt":
|
|
1
|
+
{"generatedAt":1782983649503,"builder":{"name":"webpack5"},"hasCustomBabel":false,"hasCustomWebpack":true,"hasStaticDirs":false,"hasStorybookEslint":false,"refCount":0,"metaFramework":{"name":"Gatsby","packageName":"gatsby","version":"5.13.6"},"monorepo":"Workspaces","packageManager":{"type":"yarn","version":"1.22.19"},"storybookVersion":"6.5.16","language":"javascript","storybookPackages":{"@storybook/addon-actions":{"version":"6.5.16"},"@storybook/builder-webpack5":{"version":"6.5.16"},"@storybook/manager-webpack5":{"version":"6.5.16"},"@storybook/react":{"version":"6.5.16"}},"framework":{"name":"react"},"addons":{"@storybook/addon-links":{"version":"6.5.16"},"@storybook/addon-essentials":{"version":"6.5.16"}}}
|