Skip to content

Commit cdd10f0

Browse files
committed
This fixes several interrelated problems: 1. many storybook pages were broken due to them not being kept up to date with components. all pages now display correctly and no console warnings/errors are printed (migration away from old-style required React prop-types was part of this). this should make quick QA verification possible; 2. storybook has been updated to eliminate some race conditions, which necessitated updating webpack, babel, and some older modules whose CommonJS exports were no longer acceptable. Some of these upgrade are incrementally toward updating react-admin (a future PR goal), so it's all good. 3. to clean up the webpack config, the browserlistrc has been updated to exclude pre-WebGL2 and pre-ES7 browsers. This should reduce the bundle size and have a runtime performance uplift since more built-ins will be used instead of JS fallbacks.
1 parent 86623a0 commit cdd10f0

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

45 files changed

+14595
-21270
lines changed

.browserslistrc

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
1-
last 2 major versions
2-
not <= 0.5%
3-
not dead
4-
# No WebRTC support (including datachannel
5-
not ios_saf < 11
6-
not safari < 11
1+
# Modern browsers - macOS 10.15 (Safari 15.6, 2012 MacBook compat) and iOS 10 (Safari 10.1 iPhone 6 compat) minimum
2+
chrome >= 91 # This was the version of Chrome on Oculus Go devices when their support was sunset
3+
safari >= 10
4+
ios >= 10
5+
firefox >= 91 # Lowered to align with Safari 15 capabilities, bump to 115 (Wolvic on HTC) when possible
6+
edge >= 91
7+
# Exclude legacy browsers
78
not ie >= 0
8-
not edge >= 0
99
not ie_mob >= 0
1010
not and_uc >= 0
1111
# No WebGL or WebRTC support
12-
not op_mini all
12+
not op_mini all

.storybook/main.js

Lines changed: 77 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
const path = require("path");
22
const fs = require("fs");
3+
const webpack = require("webpack");
34
const themesPath = path.resolve(__dirname, "..", "themes.json");
45
if (fs.existsSync(themesPath)) {
56
const appConfig = {};
@@ -10,8 +11,53 @@ if (fs.existsSync(themesPath)) {
1011
}
1112
module.exports = {
1213
stories: ["../src/react-components/**/*.stories.mdx", "../src/react-components/**/*.stories.js"],
13-
addons: ["@storybook/addon-links", "@storybook/addon-essentials"],
14+
addons: ["@storybook/addon-links", "@storybook/addon-docs"],
1415
webpackFinal: async config => {
16+
// Add explicit babel-loader rule for JS files with JSX at the beginning
17+
config.module.rules.unshift({
18+
test: /\.(js|jsx)$/,
19+
exclude: /node_modules/,
20+
use: {
21+
loader: "babel-loader",
22+
options: {
23+
presets: [
24+
["@babel/preset-env", { targets: "defaults" }],
25+
["@babel/preset-react", { runtime: "automatic" }]
26+
],
27+
plugins: [
28+
"formatjs",
29+
["@babel/plugin-proposal-private-property-in-object", { loose: true }],
30+
["@babel/plugin-proposal-private-methods", { loose: true }]
31+
]
32+
}
33+
}
34+
});
35+
36+
// Find and update the existing babel rule to handle JSX properly
37+
const jsRule = config.module.rules.find(
38+
rule => rule.test && rule.test.toString().includes("js") && !rule.test.toString().includes("node_modules")
39+
);
40+
41+
if (jsRule) {
42+
// Make sure it handles .js files with JSX
43+
jsRule.test = /\.(js|jsx|ts|tsx)$/;
44+
if (jsRule.use && Array.isArray(jsRule.use)) {
45+
const babelLoader = jsRule.use.find(
46+
loader => typeof loader === "object" && loader.loader && loader.loader.includes("babel")
47+
);
48+
if (babelLoader && babelLoader.options) {
49+
// Ensure React preset is configured for JSX
50+
babelLoader.options.presets = babelLoader.options.presets || [];
51+
const hasReactPreset = babelLoader.options.presets.some(preset =>
52+
Array.isArray(preset) ? preset[0].includes("react") : preset.includes("react")
53+
);
54+
if (!hasReactPreset) {
55+
babelLoader.options.presets.push(["@babel/preset-react", { runtime: "automatic" }]);
56+
}
57+
}
58+
}
59+
}
60+
1561
config.module.rules.push({
1662
test: /\.scss$/,
1763
use: [
@@ -23,7 +69,10 @@ module.exports = {
2369
localIdentName: "[name]__[local]__[hash:base64:5]",
2470
exportLocalsConvention: "camelCase",
2571
// TODO we ideally would be able to get rid of this but we have some global styles and many :local's that would become superfluous
26-
mode: "global"
72+
mode: "global",
73+
// Restore default export behavior for css-loader 7 compatibility
74+
namedExport: false,
75+
exportOnlyLocals: false
2776
}
2877
}
2978
},
@@ -69,10 +118,36 @@ module.exports = {
69118
use: ["file-loader"],
70119
include: path.resolve(__dirname, "../")
71120
});
121+
122+
// Add DefinePlugin to provide process.env variables
123+
config.plugins.push(
124+
new webpack.DefinePlugin({
125+
"process.env": {
126+
NODE_ENV: JSON.stringify("development"),
127+
RETICULUM_SERVER: JSON.stringify(""),
128+
THUMBNAIL_SERVER: JSON.stringify(""),
129+
CORS_PROXY_SERVER: JSON.stringify(""),
130+
NON_CORS_PROXY_DOMAINS: JSON.stringify(""),
131+
SENTRY_DSN: JSON.stringify(""),
132+
GA_TRACKING_ID: JSON.stringify(""),
133+
SHORTLINK_DOMAIN: JSON.stringify(""),
134+
BASE_ASSETS_PATH: JSON.stringify(""),
135+
UPLOADS_HOST: JSON.stringify(""),
136+
APP_CONFIG: JSON.stringify("")
137+
}
138+
})
139+
);
140+
72141
return config;
73142
},
74143
framework: {
75144
name: "@storybook/react-webpack5",
76145
options: {}
146+
},
147+
babel: async options => {
148+
return {
149+
...options,
150+
presets: [...options.presets, ["@babel/preset-react", { runtime: "automatic" }]]
151+
};
77152
}
78153
};

.storybook/preview.js

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import React, { useEffect } from "react";
22
import { useAccessibleOutlineStyle } from "../src/react-components/input/useAccessibleOutlineStyle";
33
import { WrappedIntlProvider } from "../src/react-components/wrapped-intl-provider";
4-
import { MINIMAL_VIEWPORTS } from "@storybook/addon-viewport";
4+
import { MINIMAL_VIEWPORTS } from "storybook/viewport";
55
import { AVAILABLE_LOCALES } from "../src/assets/locales/locale_config";
66
import { setLocale } from "../src/utils/i18n";
77
import { themes } from "../src/utils/theme";
@@ -13,12 +13,9 @@ const Layout = ({ children, locale, theme }) => {
1313

1414
useAccessibleOutlineStyle();
1515

16-
useEffect(
17-
() => {
18-
setLocale(locale);
19-
},
20-
[locale]
21-
);
16+
useEffect(() => {
17+
setLocale(locale);
18+
}, [locale]);
2219

2320
return <WrappedIntlProvider>{children}</WrappedIntlProvider>;
2421
};

.vscode/settings.json

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,5 +17,7 @@
1717
},
1818
"[html]": {
1919
"editor.defaultFormatter": "vscode.html-language-features" // Set to esbenp.prettier-vscode when we are ready to reformat all HTML files
20-
}
20+
},
21+
"i18n-ally.localesPaths": ["src/assets/locales"],
22+
"i18n-ally.keystyle": "nested"
2123
}

0 commit comments

Comments
 (0)