Skip to content

Commit f6d0874

Browse files
authored
fix: Theming - switched from ?inline to ?raw css imports (#1600)
It seems that Enterprise does not handle css ?inline css imports in node_modules the same way it does in src. Namely, the raw content gets imported as an empty string instead of the raw content. - Converted ?inline imports to ?raw. These seem to handle the raw content as expected even if in node_modules - Added a sass minification step to @deephaven/components. Vite seems to minify ?inline imports but does not do so with raw - Added a try / catch to MonacoUtils to avoid non-hex theme variables from crashing the entire app fixes #1599 BREAKING CHANGE: Theme css imports were switched from `?inline` to `?raw`. Not likely that we have any consumers yet, but this would impact webpack config.
1 parent ef52749 commit f6d0874

7 files changed

Lines changed: 81 additions & 13 deletions

File tree

jest.config.base.cjs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,12 +9,12 @@ module.exports = {
99
'node_modules/(?!(monaco-editor|d3-interpolate|d3-color)/)',
1010
],
1111
moduleNameMapper: {
12-
'theme-([^/]+?)\\.css(\\?inline)?$': path.join(
12+
'theme-([^/]+?)\\.css(\\?(?:inline|raw))?$': path.join(
1313
__dirname,
1414
'./__mocks__/css/mock-theme-$1.js'
1515
),
1616
'\\.(css|less|scss|sass)$': 'identity-obj-proxy',
17-
'\\.(css|less|scss|sass)\\?inline$': path.join(
17+
'\\.(css|less|scss|sass)\\?(?:inline|raw)$': path.join(
1818
__dirname,
1919
'./__mocks__/fileMock.js'
2020
),

packages/babel-preset/index.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ module.exports = api => ({
4141
'transform-rename-import',
4242
{
4343
// The babel-plugin-add-import-extension adds the .js to .scss imports, just convert them back to .css
44-
original: '^(.+?)\\.s?css(\\?inline)?\\.js$',
44+
original: '^(.+?)\\.s?css(\\?(?:inline|raw))?\\.js$',
4545
replacement: '$1.css$2',
4646
},
4747
],

packages/components/package.json

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,10 @@
1818
"node": ">=10"
1919
},
2020
"scripts": {
21-
"build": "cross-env NODE_ENV=production run-p build:*",
21+
"build": "cross-env NODE_ENV=production run-s build:babel build:sass build:theme",
2222
"build:babel": "babel ./src --out-dir ./dist --extensions \".ts,.tsx,.js,.jsx\" --source-maps --root-mode upward",
23-
"build:sass": "sass --embed-sources --load-path=../../node_modules ./src:./dist ./scss/BaseStyleSheet.scss:./css/BaseStyleSheet.css"
23+
"build:sass": "sass --embed-sources --load-path=../../node_modules ./src:./dist ./scss/BaseStyleSheet.scss:./css/BaseStyleSheet.css",
24+
"build:theme": "sass --embed-sources --style=compressed --load-path=../../node_modules ./src/theme:./dist/theme"
2425
},
2526
"dependencies": {
2627
"@adobe/react-spectrum": "^3.29.0",

packages/components/src/declaration.d.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,4 +17,14 @@ declare module '*.scss?inline' {
1717
export default content;
1818
}
1919

20+
declare module '*.css?raw' {
21+
const content: string;
22+
export default content;
23+
}
24+
25+
declare module '*.scss?raw' {
26+
const content: string;
27+
export default content;
28+
}
29+
2030
declare module '*.scss';

packages/components/src/theme/theme-dark/index.ts

Lines changed: 19 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,27 @@
1-
import themeDarkPalette from './theme-dark-palette.css?inline';
2-
import themeDarkSemantic from './theme-dark-semantic.css?inline';
3-
import themeDarkSemanticEditor from './theme-dark-semantic-editor.css?inline';
4-
import themeDarkSemanticGrid from './theme-dark-semantic-grid.css?inline';
5-
import themeDarkComponents from './theme-dark-components.css?inline';
1+
import themeDarkPalette from './theme-dark-palette.css?raw';
2+
import themeDarkSemantic from './theme-dark-semantic.css?raw';
3+
import themeDarkSemanticEditor from './theme-dark-semantic-editor.css?raw';
4+
import themeDarkSemanticGrid from './theme-dark-semantic-grid.css?raw';
5+
import themeDarkComponents from './theme-dark-components.css?raw';
66

77
/**
8-
* DH theme variables are imported via Vite `?inline` query which provides the
8+
* DH theme variables are imported via Vite `?raw` query which provides the
99
* text content of the variable files as a string. The exported theme is just a
1010
* concatenation of the contents of all of these imports.
1111
*
12+
* Note that ?raw / ?inline imports are natively supported by Vite, but consumers
13+
* of @deephaven/components using Webpack will need to add a rule to their module
14+
* config.
15+
* e.g.
16+
* module: {
17+
* rules: [
18+
* {
19+
* resourceQuery: /inline/,
20+
* type: 'asset/source',
21+
* },
22+
* ],
23+
* },
24+
*
1225
* e.g.
1326
*
1427
* :root {
Lines changed: 38 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,42 @@
1-
import themeLightPalette from './theme-light-palette.css?inline';
1+
import themeLightPalette from './theme-light-palette.css?raw';
22

3+
/**
4+
* DH theme variables are imported via Vite `?raw` query which provides the
5+
* text content of the variable files as a string. The exported theme is just a
6+
* concatenation of the contents of all of these imports.
7+
*
8+
* Note that ?raw / ?inline imports are natively supported by Vite, but consumers
9+
* of @deephaven/components using Webpack will need to add a rule to their module
10+
* config.
11+
* e.g.
12+
* module: {
13+
* rules: [
14+
* {
15+
* resourceQuery: /inline/,
16+
* type: 'asset/source',
17+
* },
18+
* ],
19+
* }
20+
*
21+
* e.g.
22+
*
23+
* :root {
24+
* --dh-color-from-light-palette: #fff;
25+
* --dh-color-from-light-palette2: #ccc;
26+
* }
27+
* :root {
28+
* --dh-color-from-light-semantic: #000;
29+
* }
30+
* :root {
31+
* --dh-color-from-light-semantic-editor: #000;
32+
* }
33+
* :root {
34+
* --dh-color-from-light-semantic-grid: #000;
35+
* }
36+
* :root {
37+
* --dh-color-from-light-components: #000;
38+
* }
39+
*/
340
export const themeLight = themeLightPalette;
441

542
export default themeLight;

packages/console/src/monaco/MonacoUtils.ts

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -163,7 +163,14 @@ class MonacoUtils {
163163
colors: dhDarkColors,
164164
});
165165

166-
monaco.editor.setTheme('dh-dark');
166+
try {
167+
monaco.editor.setTheme('dh-dark');
168+
} catch {
169+
log.error(
170+
`Failed to set 'dh-dark' Monaco theme, falling back to vs-dark`
171+
);
172+
monaco.editor.setTheme('vs-dark');
173+
}
167174

168175
registerLanguages([DbLang, PyLang, GroovyLang, LogLang, ScalaLang]);
169176

0 commit comments

Comments
 (0)