@modern-js/runtime 2.11.0 → 2.12.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 CHANGED
@@ -1,5 +1,19 @@
1
1
  # @modern-js/runtime
2
2
 
3
+ ## 2.12.0
4
+
5
+ ### Patch Changes
6
+
7
+ - 0b05ec3: fix: the SSR plugin will product some effects, disable the ssr plugin when user doesn't use ssr
8
+ fix: SSR 插件将会尝试一些副作用,如果用户没有使用它时禁用这个插件。
9
+ - 1aa0cb7: fix: beforeCreateRouter should be false after render router
10
+ fix: 在渲染 router 后,beforeCreateRouter 应该为 false
11
+ - Updated dependencies [c2ca6c8]
12
+ - Updated dependencies [6d86e34]
13
+ - @modern-js/utils@2.12.0
14
+ - @modern-js/plugin@2.12.0
15
+ - @modern-js/types@2.12.0
16
+
3
17
  ## 2.11.0
4
18
 
5
19
  ### Patch Changes
@@ -150,9 +150,10 @@ const PrefetchDataLinks = ({ matches, pathname, routeManifest }) => {
150
150
  const currentMatches = (0, import_react_router_dom.useMatches)();
151
151
  const basename = (0, import_react_router_dom.useHref)("/");
152
152
  const dataHrefs = (0, import_react.useMemo)(() => {
153
- return matches == null ? void 0 : matches.filter(
154
- (match) => match.route.loader && typeof match.route.loader === "function" && match.route.loader.length > 0
155
- ).filter((match, index) => {
153
+ return matches == null ? void 0 : matches.filter((match, index) => {
154
+ if (!match.route.loader || typeof match.route.loader !== "function" || match.route.loader.length === 0) {
155
+ return false;
156
+ }
156
157
  const currentMatch = currentMatches[index];
157
158
  if (!currentMatch || currentMatch.id !== match.route.id) {
158
159
  return true;
@@ -85,7 +85,7 @@ const routerPlugin = ({
85
85
  const getRouteApp = () => {
86
86
  return (props) => {
87
87
  var _a;
88
- beforeCreateRouter = true;
88
+ beforeCreateRouter = false;
89
89
  routes = createRoutes ? createRoutes() : (0, import_react_router_dom.createRoutesFromElements)(
90
90
  (0, import_utils.renderRoutes)({
91
91
  routesConfig: finalRouteConfig,
@@ -61,6 +61,20 @@ var cli_default = () => ({
61
61
  appContext.internalDirectory,
62
62
  "plugins"
63
63
  );
64
+ const { builder } = api.useAppContext();
65
+ const bundlerType = (builder == null ? void 0 : builder.context.bundlerType) || "webpack";
66
+ const babelConfig = bundlerType === "webpack" ? (config) => {
67
+ var _a, _b;
68
+ (_a = config.plugins) == null ? void 0 : _a.push(
69
+ import_path.default.join(__dirname, "./babel-plugin-ssr-loader-id")
70
+ );
71
+ const userConfig = api.useResolvedConfigContext();
72
+ if ((0, import_utils.isUseSSRBundle)(userConfig) && hasStringSSREntry(userConfig)) {
73
+ (_b = config.plugins) == null ? void 0 : _b.push(
74
+ require.resolve("@loadable/babel-plugin")
75
+ );
76
+ }
77
+ } : void 0;
64
78
  return {
65
79
  source: {
66
80
  alias: {
@@ -94,15 +108,7 @@ var cli_default = () => ({
94
108
  ];
95
109
  });
96
110
  },
97
- babel: (config) => {
98
- config.plugins.push(
99
- import_path.default.join(__dirname, "./babel-plugin-ssr-loader-id")
100
- );
101
- const userConfig = api.useResolvedConfigContext();
102
- if ((0, import_utils.isUseSSRBundle)(userConfig) && hasStringSSREntry(userConfig)) {
103
- config.plugins.push(require.resolve("@loadable/babel-plugin"));
104
- }
105
- }
111
+ babel: babelConfig
106
112
  }
107
113
  };
108
114
  },
@@ -390,9 +390,10 @@ var PrefetchDataLinks = function(param) {
390
390
  var currentMatches = useMatches();
391
391
  var basename = useHref("/");
392
392
  var dataHrefs = useMemo(function() {
393
- return matches === null || matches === void 0 ? void 0 : matches.filter(function(match) {
394
- return match.route.loader && typeof match.route.loader === "function" && match.route.loader.length > 0;
395
- }).filter(function(match, index) {
393
+ return matches === null || matches === void 0 ? void 0 : matches.filter(function(match, index) {
394
+ if (!match.route.loader || typeof match.route.loader !== "function" || match.route.loader.length === 0) {
395
+ return false;
396
+ }
396
397
  var currentMatch = currentMatches[index];
397
398
  if (!currentMatch || currentMatch.id !== match.route.id) {
398
399
  return true;
@@ -105,7 +105,7 @@ var routerPlugin = function(param) {
105
105
  var getRouteApp = function() {
106
106
  return function(props) {
107
107
  var _window__SERVER_DATA;
108
- beforeCreateRouter = true;
108
+ beforeCreateRouter = false;
109
109
  routes = createRoutes ? createRoutes() : createRoutesFromElements(renderRoutes({
110
110
  routesConfig: finalRouteConfig,
111
111
  props: props
@@ -110,6 +110,17 @@ var cli_default = function() {
110
110
  config: function config() {
111
111
  var appContext = api.useAppContext();
112
112
  pluginsExportsUtils = createRuntimeExportsUtils(appContext.internalDirectory, "plugins");
113
+ var builder = api.useAppContext().builder;
114
+ var bundlerType = (builder === null || builder === void 0 ? void 0 : builder.context.bundlerType) || "webpack";
115
+ var babelConfig = bundlerType === "webpack" ? function(config) {
116
+ var _config_plugins;
117
+ (_config_plugins = config.plugins) === null || _config_plugins === void 0 ? void 0 : _config_plugins.push(path.join(__dirname, "./babel-plugin-ssr-loader-id"));
118
+ var userConfig = api.useResolvedConfigContext();
119
+ if (isUseSSRBundle(userConfig) && hasStringSSREntry(userConfig)) {
120
+ var _config_plugins1;
121
+ (_config_plugins1 = config.plugins) === null || _config_plugins1 === void 0 ? void 0 : _config_plugins1.push(require.resolve("@loadable/babel-plugin"));
122
+ }
123
+ } : void 0;
113
124
  return {
114
125
  source: {
115
126
  alias: {
@@ -138,13 +149,7 @@ var cli_default = function() {
138
149
  ].concat(_toConsumableArray(rest));
139
150
  });
140
151
  },
141
- babel: function(config) {
142
- config.plugins.push(path.join(__dirname, "./babel-plugin-ssr-loader-id"));
143
- var userConfig = api.useResolvedConfigContext();
144
- if (isUseSSRBundle(userConfig) && hasStringSSREntry(userConfig)) {
145
- config.plugins.push(require.resolve("@loadable/babel-plugin"));
146
- }
147
- }
152
+ babel: babelConfig
148
153
  }
149
154
  };
150
155
  },
@@ -123,9 +123,10 @@ const PrefetchDataLinks = ({ matches, pathname, routeManifest }) => {
123
123
  const currentMatches = useMatches();
124
124
  const basename = useHref("/");
125
125
  const dataHrefs = useMemo(() => {
126
- return matches == null ? void 0 : matches.filter(
127
- (match) => match.route.loader && typeof match.route.loader === "function" && match.route.loader.length > 0
128
- ).filter((match, index) => {
126
+ return matches == null ? void 0 : matches.filter((match, index) => {
127
+ if (!match.route.loader || typeof match.route.loader !== "function" || match.route.loader.length === 0) {
128
+ return false;
129
+ }
129
130
  const currentMatch = currentMatches[index];
130
131
  if (!currentMatch || currentMatch.id !== match.route.id) {
131
132
  return true;
@@ -57,7 +57,7 @@ const routerPlugin = ({
57
57
  const getRouteApp = () => {
58
58
  return (props) => {
59
59
  var _a;
60
- beforeCreateRouter = true;
60
+ beforeCreateRouter = false;
61
61
  routes = createRoutes ? createRoutes() : createRoutesFromElements(
62
62
  renderRoutes({
63
63
  routesConfig: finalRouteConfig,
@@ -36,6 +36,20 @@ var cli_default = () => ({
36
36
  appContext.internalDirectory,
37
37
  "plugins"
38
38
  );
39
+ const { builder } = api.useAppContext();
40
+ const bundlerType = (builder == null ? void 0 : builder.context.bundlerType) || "webpack";
41
+ const babelConfig = bundlerType === "webpack" ? (config) => {
42
+ var _a, _b;
43
+ (_a = config.plugins) == null ? void 0 : _a.push(
44
+ path.join(__dirname, "./babel-plugin-ssr-loader-id")
45
+ );
46
+ const userConfig = api.useResolvedConfigContext();
47
+ if (isUseSSRBundle(userConfig) && hasStringSSREntry(userConfig)) {
48
+ (_b = config.plugins) == null ? void 0 : _b.push(
49
+ require.resolve("@loadable/babel-plugin")
50
+ );
51
+ }
52
+ } : void 0;
39
53
  return {
40
54
  source: {
41
55
  alias: {
@@ -69,15 +83,7 @@ var cli_default = () => ({
69
83
  ];
70
84
  });
71
85
  },
72
- babel: (config) => {
73
- config.plugins.push(
74
- path.join(__dirname, "./babel-plugin-ssr-loader-id")
75
- );
76
- const userConfig = api.useResolvedConfigContext();
77
- if (isUseSSRBundle(userConfig) && hasStringSSREntry(userConfig)) {
78
- config.plugins.push(require.resolve("@loadable/babel-plugin"));
79
- }
80
- }
86
+ babel: babelConfig
81
87
  }
82
88
  };
83
89
  },
package/package.json CHANGED
@@ -11,7 +11,7 @@
11
11
  "modern",
12
12
  "modern.js"
13
13
  ],
14
- "version": "2.11.0",
14
+ "version": "2.12.0",
15
15
  "engines": {
16
16
  "node": ">=14.17.6"
17
17
  },
@@ -158,9 +158,9 @@
158
158
  "react-side-effect": "^2.1.1",
159
159
  "redux-logger": "^3.0.6",
160
160
  "styled-components": "^5.3.1",
161
- "@modern-js/plugin": "2.11.0",
162
- "@modern-js/types": "2.11.0",
163
- "@modern-js/utils": "2.11.0"
161
+ "@modern-js/plugin": "2.12.0",
162
+ "@modern-js/types": "2.12.0",
163
+ "@modern-js/utils": "2.12.0"
164
164
  },
165
165
  "peerDependencies": {
166
166
  "react": ">=17",
@@ -181,11 +181,11 @@
181
181
  "react-dom": "^18",
182
182
  "ts-jest": "^29.0.5",
183
183
  "typescript": "^4",
184
- "@modern-js/app-tools": "2.11.0",
185
- "@modern-js/core": "2.11.0",
186
- "@modern-js/server-core": "2.11.0",
187
- "@scripts/build": "2.11.0",
188
- "@scripts/jest-config": "2.11.0"
184
+ "@modern-js/app-tools": "2.12.0",
185
+ "@modern-js/core": "2.12.0",
186
+ "@modern-js/server-core": "2.12.0",
187
+ "@scripts/build": "2.12.0",
188
+ "@scripts/jest-config": "2.12.0"
189
189
  },
190
190
  "sideEffects": false,
191
191
  "modernConfig": {},