Skip to content

Commit cf1dd83

Browse files
committed
fix: merge conflicts, hds cookie shim Refs: PL-240
1 parent 6cd450d commit cf1dd83

6 files changed

Lines changed: 82 additions & 10 deletions

File tree

README.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,12 @@ Launches Vitest test runner.<br>
3636
### `pnpm test:e2e`
3737
Launches [Playwright](playwright.config.js) test runner and performs browser tests.
3838

39+
### `pnpm fix-hds-shim`
40+
41+
Workaround for a packaging issue in `hds-core@6.x`: generates a missing `cookieConsent.js` file that `hds-react` expects but the package does not ship.
42+
This is run automatically by `pnpm dev` and `pnpm build`. Run it manually if you encounter a `MODULE_NOT_FOUND` error for `hds-core/lib/components/cookie-consent/cookieConsent` after installing dependencies.
43+
Can be removed once HDS publishes a fixed release.
44+
3945
## How to use
4046
For development:
4147
- Make sure packages are installed by running `pnpm install` in project root.

package.json

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -64,10 +64,10 @@
6464
"vitest": "^4.1.0"
6565
},
6666
"scripts": {
67-
"build": "rm -rf dist && pnpm update-runtime-env && pnpm build:client && pnpm build:server",
67+
"build": "rm -rf dist && pnpm fix-hds-shim && pnpm update-runtime-env && pnpm build:client && pnpm build:server",
6868
"build:client": "vite build --outDir dist/client --ssrManifest",
6969
"build:server": "vite build --ssr server/server-entry.js --outDir dist/server",
70-
"dev": "pnpm update-runtime-env && node server.mjs",
70+
"dev": "pnpm fix-hds-shim && pnpm update-runtime-env && node server.mjs",
7171
"lint": "eslint src/ server/ server.mjs --ext .js,.jsx,.mjs && prettier src/ server/ server.mjs --check",
7272
"lint:fix": "eslint src/ server/ server.mjs --ext .js,.jsx,.mjs --fix && prettier src/ server/ server.mjs --write",
7373
"preview": "NODE_ENV=production node server.mjs",
@@ -76,7 +76,8 @@
7676
"test:coverage": "pnpm test --coverage",
7777
"test:e2e:install": "playwright install",
7878
"test:e2e": "playwright test",
79-
"update-runtime-env": "esrun scripts/update-runtime-env.js"
79+
"update-runtime-env": "esrun scripts/update-runtime-env.js",
80+
"fix-hds-shim": "node scripts/fix-hds-core-cookie-consent.js"
8081
},
8182
"browserslist": [
8283
">0.2%",
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
/* eslint-disable no-console */
2+
import fs from 'fs';
3+
import path from 'path';
4+
5+
const targetDir = path.join(
6+
process.cwd(),
7+
'node_modules',
8+
'hds-core',
9+
'lib',
10+
'components',
11+
'cookie-consent'
12+
);
13+
14+
const targetFile = path.join(targetDir, 'cookieConsent.js');
15+
const cssFile = path.join(targetDir, 'cookieConsent.css');
16+
17+
if (!fs.existsSync(targetDir)) {
18+
console.error(
19+
'[fix-hds-core-cookie-consent] Failed: hds-core cookie-consent directory not found.'
20+
);
21+
process.exit(1);
22+
}
23+
if (!fs.existsSync(cssFile)) {
24+
console.error(
25+
'[fix-hds-core-cookie-consent] Failed: cookieConsent.css not found; cannot create shim.'
26+
);
27+
process.exit(1);
28+
}
29+
30+
const cssContent = fs.readFileSync(cssFile, 'utf8');
31+
const shimContent = `'use strict';\n\nconst css = ${JSON.stringify(cssContent)};\n\nmodule.exports = { __esModule: true, default: css };\n`;
32+
33+
if (!fs.existsSync(targetFile)) {
34+
fs.writeFileSync(targetFile, shimContent, 'utf8');
35+
console.log(
36+
'[fix-hds-core-cookie-consent] Created cookieConsent.js shim for hds-react compatibility.'
37+
);
38+
} else {
39+
const currentContent = fs.readFileSync(targetFile, 'utf8');
40+
41+
if (currentContent !== shimContent) {
42+
fs.writeFileSync(targetFile, shimContent, 'utf8');
43+
console.log(
44+
'[fix-hds-core-cookie-consent] Updated cookieConsent.js shim for hds-react compatibility.'
45+
);
46+
} else {
47+
console.log(
48+
'[fix-hds-core-cookie-consent] cookieConsent.js shim already up to date.'
49+
);
50+
}
51+
}

server.mjs

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,10 @@ const normalizeHeadMarkup = (headMarkup) => {
119119
if (titleTags.length <= 1) return headMarkup;
120120

121121
const lastTitleTag = titleTags[titleTags.length - 1][0];
122-
const markupWithoutTitles = headMarkup.replace(/<title[\s\S]*?<\/title>\s*/gi, '');
122+
const markupWithoutTitles = headMarkup.replace(
123+
/<title[\s\S]*?<\/title>\s*/gi,
124+
''
125+
);
123126
return `${lastTitleTag}\n${markupWithoutTitles}`;
124127
};
125128

@@ -369,7 +372,12 @@ const createServer = async () => {
369372
const cspHeaders = generateCSPHeaders(nonce);
370373

371374
const entry = await getEntry();
372-
const { render, getRequestFullUrl, parseInitialMapPositionFromHostname, ogImage } = entry;
375+
const {
376+
render,
377+
getRequestFullUrl,
378+
parseInitialMapPositionFromHostname,
379+
ogImage,
380+
} = entry;
373381

374382
let template;
375383
if (isProd) {
@@ -395,8 +403,13 @@ const createServer = async () => {
395403
initialMapPosition: parseInitialMapPositionFromHostname(req, Sentry),
396404
};
397405

398-
const { html: rawHtml, helmet, emotionCss } = await render(req.url, { store, nonce, locale });
399-
const { headMarkup: reactHeadMarkup, appMarkup } = extractHeadMarkupFromReactDom(rawHtml);
406+
const {
407+
html: rawHtml,
408+
helmet,
409+
emotionCss,
410+
} = await render(req.url, { store, nonce, locale });
411+
const { headMarkup: reactHeadMarkup, appMarkup } =
412+
extractHeadMarkupFromReactDom(rawHtml);
400413
// React 19 hoists head tags into render output; fall back to Helmet context for older behaviour.
401414
const helmetHeadMarkup = helmet
402415
? `${helmet.title.toString()}${helmet.meta.toString()}`

src/store.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { applyMiddleware, createStore } from 'redux';
2-
import thunk from 'redux-thunk';
2+
import { thunk } from 'redux-thunk';
33

44
import rootReducer from './redux/rootReducer';
55

vite.config.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,10 +19,11 @@ export default defineConfig(({ isSsrBuild }) => ({
1919
}),
2020
// Fix CJS/ESM interop for packages that use lazy-getter or module.exports patterns
2121
// that don't survive Vite's SSR externalization (named ESM imports would fail at runtime).
22+
// Note: react-helmet-async and redux-thunk both ship proper ESM via their exports map
23+
// and must NOT be listed here — cjsInterop would emit `import default` which has no
24+
// default export in their ESM entries.
2225
cjsInterop({
2326
dependencies: [
24-
'react-helmet-async',
25-
'redux-thunk',
2627
'@mui/styled-engine',
2728
],
2829
}),

0 commit comments

Comments
 (0)