Skip to content

Commit 70307b1

Browse files
committed
feat: no more css
1 parent 59ecefa commit 70307b1

File tree

4 files changed

+27
-24
lines changed

4 files changed

+27
-24
lines changed

packages/commerce-sdk-react/src/types/css.d.ts

Lines changed: 0 additions & 12 deletions
This file was deleted.

packages/pwa-kit-dev/package.json

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,6 @@
7070
"commander": "^9.5.0",
7171
"compression": "1.7.4",
7272
"copy-webpack-plugin": "^9.1.0",
73-
"css-loader": "^6.8.1",
7473
"cross-env": "^5.2.1",
7574
"eslint": "^8.37.0",
7675
"eslint-config-prettier": "8.8.0",
@@ -102,7 +101,6 @@
102101
"semver": "^7.5.2",
103102
"source-map-loader": "^4.0.1",
104103
"speed-measure-webpack-plugin": "^1.5.0",
105-
"style-loader": "^3.3.3",
106104
"svg-sprite-loader": "^6.0.11",
107105
"validator": "^13.9.0",
108106
"webpack": "^5.76.3",

packages/pwa-kit-dev/src/configs/webpack/config.js

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -280,11 +280,7 @@ const baseConfig = (target) => {
280280
loader: findDepInStack('source-map-loader')
281281
}
282282
},
283-
target === 'web' && {
284-
test: /\.css$/,
285-
use: [findDepInStack('style-loader'), findDepInStack('css-loader')]
286-
},
287-
target === 'node' && {
283+
{
288284
test: /\.css$/,
289285
loader: findDepInStack('ignore-loader')
290286
}
@@ -358,6 +354,15 @@ const staticFolderCopyPlugin = new CopyPlugin({
358354
.replace(/\\/g, '/'),
359355
to: `static/`,
360356
noErrorOnMissing: true
357+
},
358+
{
359+
// Copy Page Designer CSS from storefront-next-runtime for dynamic loading
360+
from: path.resolve(
361+
projectDir,
362+
'node_modules/@salesforce/storefront-next-runtime/dist/design-styles.css'
363+
),
364+
to: 'static/pd-design-styles.css',
365+
noErrorOnMissing: true
361366
}
362367
]
363368
})

packages/template-retail-react-app/app/components/page-designer-init/index.jsx

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import {
1111
usePageDesignerMode,
1212
useGlobalAnchorBlock
1313
} from '@salesforce/commerce-sdk-react/page-designer'
14+
import {getAssetUrl} from '@salesforce/pwa-kit-react-sdk/ssr/universal/utils'
1415

1516
/**
1617
* PageDesignerInit - Component that handles Page Designer initialization
@@ -59,14 +60,25 @@ export function PageDesignerInit() {
5960
// Pass isDesignMode to control when navigation blocking is active
6061
useGlobalAnchorBlock(isDesignMode)
6162

62-
// Dynamically import the Page Designer global styles only when in design mode.
63+
// Dynamically load the Page Designer global styles only when in design mode.
6364
// This ensures the styles are not loaded in production runtime, improving performance.
6465
useEffect(() => {
65-
if (isDesignMode) {
66-
// Dynamic import with void to ignore the promise
67-
// Import only the CSS file, not the entire components module to avoid circular dependencies
68-
void import('@salesforce/storefront-next-runtime/design/styles.css')
66+
if (!isDesignMode) {
67+
return
6968
}
69+
70+
const id = 'pd-design-styles'
71+
if (document.getElementById(id)) {
72+
return
73+
}
74+
75+
const link = document.createElement('link')
76+
link.id = id
77+
link.rel = 'stylesheet'
78+
link.href = getAssetUrl('static/pd-design-styles.css')
79+
document.head.appendChild(link)
80+
81+
return () => link.remove()
7082
}, [isDesignMode])
7183

7284
// When the message function returns false, navigation is completely blocked (no dialog shown)

0 commit comments

Comments
 (0)