@docusaurus/core 3.3.0 → 3.3.2

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.
@@ -4,7 +4,7 @@
4
4
  * This source code is licensed under the MIT license found in the
5
5
  * LICENSE file in the root directory of this source tree.
6
6
  */
7
- import React from 'react';
7
+ import React, { startTransition } from 'react';
8
8
  import ReactDOM from 'react-dom/client';
9
9
  import { BrowserRouter } from 'react-router-dom';
10
10
  import { HelmetProvider } from 'react-helmet-async';
@@ -27,21 +27,24 @@ if (ExecutionEnvironment.canUseDOM) {
27
27
  console.error('Docusaurus React Root onRecoverableError:', error, errorInfo);
28
28
  };
29
29
  const renderApp = () => {
30
+ if (window.docusaurusRoot) {
31
+ window.docusaurusRoot.render(app);
32
+ return;
33
+ }
30
34
  if (hydrate) {
31
- React.startTransition(() => {
32
- ReactDOM.hydrateRoot(container, app, {
33
- onRecoverableError,
34
- });
35
+ window.docusaurusRoot = ReactDOM.hydrateRoot(container, app, {
36
+ onRecoverableError,
35
37
  });
36
38
  }
37
39
  else {
38
40
  const root = ReactDOM.createRoot(container, { onRecoverableError });
39
- React.startTransition(() => {
40
- root.render(app);
41
- });
41
+ root.render(app);
42
+ window.docusaurusRoot = root;
42
43
  }
43
44
  };
44
- preload(window.location.pathname).then(renderApp);
45
+ preload(window.location.pathname).then(() => {
46
+ startTransition(renderApp);
47
+ });
45
48
  // Webpack Hot Module Replacement API
46
49
  if (module.hot) {
47
50
  // Self-accepting method/ trick
@@ -16,7 +16,7 @@ declare global {
16
16
  }
17
17
  }
18
18
  declare const _default: Readonly<{
19
- prefetch(routePath: string): false | Promise<void[]>;
20
- preload(routePath: string): false | Promise<void[]>;
19
+ prefetch: (url: string) => false | Promise<void[]>;
20
+ preload: (url: string) => false | Promise<void[]>;
21
21
  }>;
22
22
  export default _default;
@@ -24,37 +24,39 @@ const getChunkNamesToLoad = (path) => Object.entries(routesChunkNames)
24
24
  // output: /blog/2018/12/14/Happy-First-Birthday-Slash
25
25
  ([routeNameWithHash]) => routeNameWithHash.replace(/-[^-]+$/, '') === path)
26
26
  .flatMap(([, routeChunks]) => Object.values(flat(routeChunks)));
27
- const docusaurus = {
28
- prefetch(routePath) {
29
- if (!canPrefetch(routePath)) {
30
- return false;
31
- }
32
- fetched.add(routePath);
33
- // Find all webpack chunk names needed.
34
- const matches = matchRoutes(routes, routePath);
35
- const chunkNamesNeeded = matches.flatMap((match) => getChunkNamesToLoad(match.route.path));
36
- // Prefetch all webpack chunk assets file needed.
37
- return Promise.all(chunkNamesNeeded.map((chunkName) => {
38
- // "__webpack_require__.gca" is injected by ChunkAssetPlugin. Pass it
39
- // the name of the chunk you want to load and it will return its URL.
40
- // eslint-disable-next-line camelcase
41
- const chunkAsset = __webpack_require__.gca(chunkName);
42
- // In some cases, webpack might decide to optimize further, leading to
43
- // the chunk assets being merged to another chunk. In this case, we can
44
- // safely filter it out and don't need to load it.
45
- if (chunkAsset && !chunkAsset.includes('undefined')) {
46
- return prefetchHelper(chunkAsset);
47
- }
48
- return Promise.resolve();
49
- }));
50
- },
51
- preload(routePath) {
52
- if (!canPreload(routePath)) {
53
- return false;
27
+ const prefetch = (routePath) => {
28
+ if (!canPrefetch(routePath)) {
29
+ return false;
30
+ }
31
+ fetched.add(routePath);
32
+ // Find all webpack chunk names needed.
33
+ const matches = matchRoutes(routes, routePath);
34
+ const chunkNamesNeeded = matches.flatMap((match) => getChunkNamesToLoad(match.route.path));
35
+ // Prefetch all webpack chunk assets file needed.
36
+ return Promise.all(chunkNamesNeeded.map((chunkName) => {
37
+ // "__webpack_require__.gca" is injected by ChunkAssetPlugin. Pass it
38
+ // the name of the chunk you want to load and it will return its URL.
39
+ // eslint-disable-next-line camelcase
40
+ const chunkAsset = __webpack_require__.gca(chunkName);
41
+ // In some cases, webpack might decide to optimize further, leading to
42
+ // the chunk assets being merged to another chunk. In this case, we can
43
+ // safely filter it out and don't need to load it.
44
+ if (chunkAsset && !chunkAsset.includes('undefined')) {
45
+ return prefetchHelper(chunkAsset);
54
46
  }
55
- loaded.add(routePath);
56
- return preloadHelper(routePath);
57
- },
47
+ return Promise.resolve();
48
+ }));
49
+ };
50
+ const preload = (routePath) => {
51
+ if (!canPreload(routePath)) {
52
+ return false;
53
+ }
54
+ loaded.add(routePath);
55
+ return preloadHelper(routePath);
56
+ };
57
+ const docusaurus = {
58
+ prefetch,
59
+ preload,
58
60
  };
59
61
  // This object is directly mounted onto window, better freeze it
60
62
  export default Object.freeze(docusaurus);
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.3.0",
4
+ "version": "3.3.2",
5
5
  "license": "MIT",
6
6
  "publishConfig": {
7
7
  "access": "public"
@@ -43,12 +43,12 @@
43
43
  "@babel/runtime": "^7.22.6",
44
44
  "@babel/runtime-corejs3": "^7.22.6",
45
45
  "@babel/traverse": "^7.22.8",
46
- "@docusaurus/cssnano-preset": "3.3.0",
47
- "@docusaurus/logger": "3.3.0",
48
- "@docusaurus/mdx-loader": "3.3.0",
49
- "@docusaurus/utils": "3.3.0",
50
- "@docusaurus/utils-common": "3.3.0",
51
- "@docusaurus/utils-validation": "3.3.0",
46
+ "@docusaurus/cssnano-preset": "3.3.2",
47
+ "@docusaurus/logger": "3.3.2",
48
+ "@docusaurus/mdx-loader": "3.3.2",
49
+ "@docusaurus/utils": "3.3.2",
50
+ "@docusaurus/utils-common": "3.3.2",
51
+ "@docusaurus/utils-validation": "3.3.2",
52
52
  "autoprefixer": "^10.4.14",
53
53
  "babel-loader": "^9.1.3",
54
54
  "babel-plugin-dynamic-import-node": "^2.3.3",
@@ -103,8 +103,8 @@
103
103
  "webpackbar": "^5.0.2"
104
104
  },
105
105
  "devDependencies": {
106
- "@docusaurus/module-type-aliases": "3.3.0",
107
- "@docusaurus/types": "3.3.0",
106
+ "@docusaurus/module-type-aliases": "3.3.2",
107
+ "@docusaurus/types": "3.3.2",
108
108
  "@total-typescript/shoehorn": "^0.1.2",
109
109
  "@types/detect-port": "^1.3.3",
110
110
  "@types/react-dom": "^18.2.7",
@@ -124,5 +124,5 @@
124
124
  "engines": {
125
125
  "node": ">=18.0"
126
126
  },
127
- "gitHead": "2ec4e078b5ca0c57f2cc04f2fe564d524bb5e858"
127
+ "gitHead": "bc638d674bfbde1e254ef306697f47e764b5e107"
128
128
  }