@docusaurus/core 3.6.3-canary-6159 → 3.6.3-canary-6161
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/lib/server/codegen/codegenRoutes.js +28 -5
- package/package.json +11 -11
|
@@ -116,14 +116,37 @@ function genChunkNames(routeModule, prefix, name, res) {
|
|
|
116
116
|
* config node, it returns the node's serialized form, and mutates `registry`,
|
|
117
117
|
* `routesPaths`, and `routesChunkNames` accordingly.
|
|
118
118
|
*/
|
|
119
|
-
function genRouteCode(routeConfig, res) {
|
|
119
|
+
function genRouteCode(routeConfig, res, index, level) {
|
|
120
120
|
const { path: routePath, component, modules = {}, context, routes: subroutes, priority, exact, metadata, props, plugin, ...attributes } = routeConfig;
|
|
121
121
|
if (typeof routePath !== 'string' || !component) {
|
|
122
122
|
throw new Error(`Invalid route config: path must be a string and component is required.
|
|
123
123
|
${JSON.stringify(routeConfig)}`);
|
|
124
124
|
}
|
|
125
|
-
|
|
126
|
-
|
|
125
|
+
// Because 2 routes with the same path could lead to hash collisions
|
|
126
|
+
// See https://github.com/facebook/docusaurus/issues/10718#issuecomment-2498516394
|
|
127
|
+
function generateUniqueRouteKey() {
|
|
128
|
+
const hashes = [
|
|
129
|
+
// // OG algo to keep former snapshots
|
|
130
|
+
() => (0, utils_1.simpleHash)(JSON.stringify(routeConfig), 3),
|
|
131
|
+
// Other attempts, not ideal but good enough
|
|
132
|
+
// Technically we could use Math.random() here but it's annoying for tests
|
|
133
|
+
() => (0, utils_1.simpleHash)(`${level}${index}`, 3),
|
|
134
|
+
() => (0, utils_1.simpleHash)(JSON.stringify(routeConfig), 4),
|
|
135
|
+
() => (0, utils_1.simpleHash)(`${level}${index}`, 4),
|
|
136
|
+
];
|
|
137
|
+
for (const tryHash of hashes) {
|
|
138
|
+
const routeHash = tryHash();
|
|
139
|
+
const routeKey = `${routePath}-${routeHash}`;
|
|
140
|
+
if (!res.routesChunkNames[routeKey]) {
|
|
141
|
+
return { routeKey, routeHash };
|
|
142
|
+
}
|
|
143
|
+
}
|
|
144
|
+
throw new Error(`Docusaurus couldn't generate a unique hash for route ${routeConfig.path} (level=${level} - index=${index}).
|
|
145
|
+
This is a bug, please report it here!
|
|
146
|
+
https://github.com/facebook/docusaurus/issues/10718`);
|
|
147
|
+
}
|
|
148
|
+
const { routeKey, routeHash } = generateUniqueRouteKey();
|
|
149
|
+
res.routesChunkNames[routeKey] = {
|
|
127
150
|
// Avoid clash with a prop called "component"
|
|
128
151
|
...genChunkNames({ __comp: component }, 'component', component, res),
|
|
129
152
|
...(context &&
|
|
@@ -133,7 +156,7 @@ ${JSON.stringify(routeConfig)}`);
|
|
|
133
156
|
return serializeRouteConfig({
|
|
134
157
|
routePath: routePath.replace(/'/g, "\\'"),
|
|
135
158
|
routeHash,
|
|
136
|
-
subroutesCodeStrings: subroutes?.map((r) => genRouteCode(r, res)),
|
|
159
|
+
subroutesCodeStrings: subroutes?.map((r, i) => genRouteCode(r, res, i, level + 1)),
|
|
137
160
|
exact,
|
|
138
161
|
attributes,
|
|
139
162
|
});
|
|
@@ -156,7 +179,7 @@ function generateRoutesCode(routeConfigs) {
|
|
|
156
179
|
};
|
|
157
180
|
// `genRouteCode` would mutate `res`
|
|
158
181
|
const routeConfigSerialized = routeConfigs
|
|
159
|
-
.map((r) => genRouteCode(r, res))
|
|
182
|
+
.map((r, i) => genRouteCode(r, res, i, 0))
|
|
160
183
|
.join(',\n');
|
|
161
184
|
res.routesConfig = `import React from 'react';
|
|
162
185
|
import ComponentCreator from '@docusaurus/ComponentCreator';
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@docusaurus/core",
|
|
3
3
|
"description": "Easy to Maintain Open Source Documentation Websites",
|
|
4
|
-
"version": "3.6.3-canary-
|
|
4
|
+
"version": "3.6.3-canary-6161",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"publishConfig": {
|
|
7
7
|
"access": "public"
|
|
@@ -33,13 +33,13 @@
|
|
|
33
33
|
"url": "https://github.com/facebook/docusaurus/issues"
|
|
34
34
|
},
|
|
35
35
|
"dependencies": {
|
|
36
|
-
"@docusaurus/babel": "3.6.3-canary-
|
|
37
|
-
"@docusaurus/bundler": "3.6.3-canary-
|
|
38
|
-
"@docusaurus/logger": "3.6.3-canary-
|
|
39
|
-
"@docusaurus/mdx-loader": "3.6.3-canary-
|
|
40
|
-
"@docusaurus/utils": "3.6.3-canary-
|
|
41
|
-
"@docusaurus/utils-common": "3.6.3-canary-
|
|
42
|
-
"@docusaurus/utils-validation": "3.6.3-canary-
|
|
36
|
+
"@docusaurus/babel": "3.6.3-canary-6161",
|
|
37
|
+
"@docusaurus/bundler": "3.6.3-canary-6161",
|
|
38
|
+
"@docusaurus/logger": "3.6.3-canary-6161",
|
|
39
|
+
"@docusaurus/mdx-loader": "3.6.3-canary-6161",
|
|
40
|
+
"@docusaurus/utils": "3.6.3-canary-6161",
|
|
41
|
+
"@docusaurus/utils-common": "3.6.3-canary-6161",
|
|
42
|
+
"@docusaurus/utils-validation": "3.6.3-canary-6161",
|
|
43
43
|
"boxen": "^6.2.1",
|
|
44
44
|
"chalk": "^4.1.2",
|
|
45
45
|
"chokidar": "^3.5.3",
|
|
@@ -78,8 +78,8 @@
|
|
|
78
78
|
"webpack-merge": "^6.0.1"
|
|
79
79
|
},
|
|
80
80
|
"devDependencies": {
|
|
81
|
-
"@docusaurus/module-type-aliases": "3.6.3-canary-
|
|
82
|
-
"@docusaurus/types": "3.6.3-canary-
|
|
81
|
+
"@docusaurus/module-type-aliases": "3.6.3-canary-6161",
|
|
82
|
+
"@docusaurus/types": "3.6.3-canary-6161",
|
|
83
83
|
"@total-typescript/shoehorn": "^0.1.2",
|
|
84
84
|
"@types/detect-port": "^1.3.3",
|
|
85
85
|
"@types/react-dom": "^18.2.7",
|
|
@@ -100,5 +100,5 @@
|
|
|
100
100
|
"engines": {
|
|
101
101
|
"node": ">=18.0"
|
|
102
102
|
},
|
|
103
|
-
"gitHead": "
|
|
103
|
+
"gitHead": "b4865dd557c63a1f2bfd6078da6048398fdc0ed0"
|
|
104
104
|
}
|