@docusaurus/core 4.0.0-canary-6839 → 4.0.0-canary-6841
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/client/App.js +9 -12
- package/lib/client/exports/useIsBrowser.js +9 -3
- package/lib/commands/start/utils.d.ts +0 -3
- package/lib/commands/start/utils.js +0 -1
- package/lib/commands/start/watcher.d.ts +1 -17
- package/lib/commands/start/watcher.js +0 -3
- package/lib/commands/swizzle/components.d.ts +0 -1
- package/lib/commands/swizzle/components.js +0 -1
- package/lib/commands/swizzle/themes.d.ts +0 -1
- package/lib/commands/swizzle/themes.js +0 -1
- package/lib/server/configValidation.d.ts +1 -4
- package/lib/server/configValidation.js +8 -8
- package/lib/server/translations/translations.d.ts +0 -1
- package/lib/server/translations/translations.js +0 -1
- package/lib/ssg/ssgTemplate.d.ts +2 -1
- package/package.json +15 -14
- package/lib/client/browserContext.d.ts +0 -11
- package/lib/client/browserContext.js +0 -22
package/lib/client/App.js
CHANGED
|
@@ -13,7 +13,6 @@ import Root from '@theme/Root';
|
|
|
13
13
|
import ThemeProvider from '@theme/ThemeProvider';
|
|
14
14
|
import SiteMetadata from '@theme/SiteMetadata';
|
|
15
15
|
import normalizeLocation from './normalizeLocation';
|
|
16
|
-
import { BrowserContextProvider } from './browserContext';
|
|
17
16
|
import { DocusaurusContextProvider } from './docusaurusContext';
|
|
18
17
|
import PendingNavigation from './PendingNavigation';
|
|
19
18
|
import BaseUrlIssueBanner from './BaseUrlIssueBanner';
|
|
@@ -33,17 +32,15 @@ function AppNavigation() {
|
|
|
33
32
|
export default function App() {
|
|
34
33
|
return (<ErrorBoundary>
|
|
35
34
|
<DocusaurusContextProvider>
|
|
36
|
-
<
|
|
37
|
-
<
|
|
38
|
-
<
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
<HasHydratedDataAttribute />
|
|
46
|
-
</BrowserContextProvider>
|
|
35
|
+
<Root>
|
|
36
|
+
<ThemeProvider>
|
|
37
|
+
<SiteMetadataDefaults />
|
|
38
|
+
<SiteMetadata />
|
|
39
|
+
<BaseUrlIssueBanner />
|
|
40
|
+
<AppNavigation />
|
|
41
|
+
</ThemeProvider>
|
|
42
|
+
</Root>
|
|
43
|
+
<HasHydratedDataAttribute />
|
|
47
44
|
</DocusaurusContextProvider>
|
|
48
45
|
</ErrorBoundary>);
|
|
49
46
|
}
|
|
@@ -4,8 +4,14 @@
|
|
|
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 {
|
|
8
|
-
|
|
7
|
+
import { useSyncExternalStore } from 'react';
|
|
8
|
+
// The "browser" state never changes, there's nothing to subscribe to
|
|
9
|
+
const subscribe = () => () => { };
|
|
10
|
+
// On first client-side render, we need to render exactly as the server rendered
|
|
11
|
+
// See https://www.joshwcomeau.com/react/the-perils-of-rehydration/
|
|
12
|
+
// React uses getServerSnapshot during SSR and hydration, and re-renders with
|
|
13
|
+
// getSnapshot right after hydration. Components mounted after hydration
|
|
14
|
+
// directly get the client value, without an extra re-render.
|
|
9
15
|
export default function useIsBrowser() {
|
|
10
|
-
return
|
|
16
|
+
return useSyncExternalStore(subscribe, () => true, () => false);
|
|
11
17
|
}
|
|
@@ -15,9 +15,6 @@ export type OpenUrlContext = {
|
|
|
15
15
|
router: RouterType;
|
|
16
16
|
}) => string;
|
|
17
17
|
};
|
|
18
|
-
export declare function createOpenUrlContext({ cliOptions, }: {
|
|
19
|
-
cliOptions: StartCLIOptions;
|
|
20
|
-
}): Promise<OpenUrlContext>;
|
|
21
18
|
type StartParams = {
|
|
22
19
|
siteDirParam: string;
|
|
23
20
|
cliOptions: Partial<StartCLIOptions>;
|
|
@@ -6,7 +6,6 @@
|
|
|
6
6
|
* LICENSE file in the root directory of this source tree.
|
|
7
7
|
*/
|
|
8
8
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
9
|
-
exports.createOpenUrlContext = createOpenUrlContext;
|
|
10
9
|
exports.createReloadableSite = createReloadableSite;
|
|
11
10
|
const tslib_1 = require("tslib");
|
|
12
11
|
const fs_extra_1 = tslib_1.__importDefault(require("fs-extra"));
|
|
@@ -11,27 +11,11 @@ type PollingOptions = {
|
|
|
11
11
|
interval: number | undefined;
|
|
12
12
|
};
|
|
13
13
|
export declare function createPollingOptions(cliOptions: StartCLIOptions): PollingOptions;
|
|
14
|
-
|
|
14
|
+
type FileWatchEventName = 'add' | 'addDir' | 'change' | 'unlink' | 'unlinkDir';
|
|
15
15
|
export type FileWatchEvent = {
|
|
16
16
|
name: FileWatchEventName;
|
|
17
17
|
path: string;
|
|
18
18
|
};
|
|
19
|
-
type WatchParams = {
|
|
20
|
-
pathsToWatch: string[];
|
|
21
|
-
siteDir: string;
|
|
22
|
-
} & PollingOptions;
|
|
23
|
-
/**
|
|
24
|
-
* Watch file system paths for changes and emit events
|
|
25
|
-
* Returns an async handle to stop watching
|
|
26
|
-
*/
|
|
27
|
-
export declare function watchPaths(params: WatchParams, callback: (event: FileWatchEvent) => void): () => Promise<void>;
|
|
28
|
-
export declare function getSitePathsToWatch({ props }: {
|
|
29
|
-
props: Props;
|
|
30
|
-
}): string[];
|
|
31
|
-
export declare function getPluginPathsToWatch({ siteDir, plugin, }: {
|
|
32
|
-
siteDir: string;
|
|
33
|
-
plugin: LoadedPlugin;
|
|
34
|
-
}): string[];
|
|
35
19
|
export declare function setupSiteFileWatchers({ props, cliOptions, }: {
|
|
36
20
|
props: Props;
|
|
37
21
|
cliOptions: StartCLIOptions;
|
|
@@ -7,9 +7,6 @@
|
|
|
7
7
|
*/
|
|
8
8
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
9
9
|
exports.createPollingOptions = createPollingOptions;
|
|
10
|
-
exports.watchPaths = watchPaths;
|
|
11
|
-
exports.getSitePathsToWatch = getSitePathsToWatch;
|
|
12
|
-
exports.getPluginPathsToWatch = getPluginPathsToWatch;
|
|
13
10
|
exports.setupSiteFileWatchers = setupSiteFileWatchers;
|
|
14
11
|
const tslib_1 = require("tslib");
|
|
15
12
|
const path_1 = tslib_1.__importDefault(require("path"));
|
|
@@ -25,7 +25,6 @@ export type ThemeComponents = {
|
|
|
25
25
|
*/
|
|
26
26
|
export declare function getMissingIntermediateComponentFolderNames(componentNames: string[]): string[];
|
|
27
27
|
export declare function readComponentNames(themePath: string): Promise<string[]>;
|
|
28
|
-
export declare function listComponentNames(themeComponents: ThemeComponents): string;
|
|
29
28
|
export declare function getThemeComponents({ themeName, themePath, swizzleConfig, }: {
|
|
30
29
|
themeName: string;
|
|
31
30
|
themePath: string;
|
|
@@ -8,7 +8,6 @@
|
|
|
8
8
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
9
9
|
exports.getMissingIntermediateComponentFolderNames = getMissingIntermediateComponentFolderNames;
|
|
10
10
|
exports.readComponentNames = readComponentNames;
|
|
11
|
-
exports.listComponentNames = listComponentNames;
|
|
12
11
|
exports.getThemeComponents = getThemeComponents;
|
|
13
12
|
exports.getComponentName = getComponentName;
|
|
14
13
|
const tslib_1 = require("tslib");
|
|
@@ -5,7 +5,6 @@
|
|
|
5
5
|
* LICENSE file in the root directory of this source tree.
|
|
6
6
|
*/
|
|
7
7
|
import { type SwizzlePlugin } from './common';
|
|
8
|
-
export declare function pluginToThemeName(plugin: SwizzlePlugin): string | undefined;
|
|
9
8
|
export declare function getPluginByThemeName(plugins: SwizzlePlugin[], themeName: string): SwizzlePlugin;
|
|
10
9
|
export declare function getThemeNames(plugins: SwizzlePlugin[]): string[];
|
|
11
10
|
export declare function getThemeName({ themeNameParam, themeNames, list, }: {
|
|
@@ -6,7 +6,6 @@
|
|
|
6
6
|
* LICENSE file in the root directory of this source tree.
|
|
7
7
|
*/
|
|
8
8
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
9
|
-
exports.pluginToThemeName = pluginToThemeName;
|
|
10
9
|
exports.getPluginByThemeName = getPluginByThemeName;
|
|
11
10
|
exports.getThemeNames = getThemeNames;
|
|
12
11
|
exports.getThemeName = getThemeName;
|
|
@@ -5,7 +5,7 @@
|
|
|
5
5
|
* LICENSE file in the root directory of this source tree.
|
|
6
6
|
*/
|
|
7
7
|
import { Joi } from '@docusaurus/utils-validation';
|
|
8
|
-
import type { DocusaurusConfig, FasterConfig, FutureConfig, FutureV4Config, I18nConfig,
|
|
8
|
+
import type { DocusaurusConfig, FasterConfig, FutureConfig, FutureV4Config, I18nConfig, StorageConfig } from '@docusaurus/types';
|
|
9
9
|
export declare const DEFAULT_I18N_CONFIG: I18nConfig;
|
|
10
10
|
export declare const DEFAULT_STORAGE_CONFIG: StorageConfig;
|
|
11
11
|
export declare const DEFAULT_FASTER_CONFIG: FasterConfig;
|
|
@@ -13,9 +13,6 @@ export declare const DEFAULT_FASTER_CONFIG_TRUE: FasterConfig;
|
|
|
13
13
|
export declare const DEFAULT_FUTURE_V4_CONFIG: FutureV4Config;
|
|
14
14
|
export declare const DEFAULT_FUTURE_V4_CONFIG_TRUE: FutureV4Config;
|
|
15
15
|
export declare const DEFAULT_FUTURE_CONFIG: FutureConfig;
|
|
16
|
-
export declare const DEFAULT_MARKDOWN_HOOKS: MarkdownHooks;
|
|
17
|
-
export declare const DEFAULT_MARKDOWN_MDX1COMPAT: MDX1CompatOptions;
|
|
18
|
-
export declare const DEFAULT_MARKDOWN_CONFIG: MarkdownConfig;
|
|
19
16
|
export declare const DEFAULT_CONFIG: Pick<DocusaurusConfig, 'i18n' | 'storage' | 'future' | 'onBrokenLinks' | 'onBrokenAnchors' | 'onBrokenMarkdownLinks' | 'onDuplicateRoutes' | 'plugins' | 'themes' | 'presets' | 'headTags' | 'stylesheets' | 'scripts' | 'clientModules' | 'customFields' | 'themeConfig' | 'titleDelimiter' | 'noIndex' | 'tagline' | 'baseUrlIssueBanner' | 'staticDirectories' | 'markdown'>;
|
|
20
17
|
export declare const ConfigSchema: Joi.ObjectSchema<DocusaurusConfig>;
|
|
21
18
|
export declare function validateConfig(config: unknown, siteConfigPath: string): DocusaurusConfig;
|
|
@@ -6,7 +6,7 @@
|
|
|
6
6
|
* LICENSE file in the root directory of this source tree.
|
|
7
7
|
*/
|
|
8
8
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
9
|
-
exports.ConfigSchema = exports.DEFAULT_CONFIG = exports.
|
|
9
|
+
exports.ConfigSchema = exports.DEFAULT_CONFIG = exports.DEFAULT_FUTURE_CONFIG = exports.DEFAULT_FUTURE_V4_CONFIG_TRUE = exports.DEFAULT_FUTURE_V4_CONFIG = exports.DEFAULT_FASTER_CONFIG_TRUE = exports.DEFAULT_FASTER_CONFIG = exports.DEFAULT_STORAGE_CONFIG = exports.DEFAULT_I18N_CONFIG = void 0;
|
|
10
10
|
exports.validateConfig = validateConfig;
|
|
11
11
|
const tslib_1 = require("tslib");
|
|
12
12
|
const utils_1 = require("@docusaurus/utils");
|
|
@@ -87,17 +87,17 @@ exports.DEFAULT_FUTURE_CONFIG = {
|
|
|
87
87
|
experimental_vcs: (0, utils_1.getVcsPreset)('default-v1'),
|
|
88
88
|
experimental_router: 'browser',
|
|
89
89
|
};
|
|
90
|
-
|
|
90
|
+
const DEFAULT_MARKDOWN_HOOKS = {
|
|
91
91
|
onBrokenMarkdownLinks: 'warn',
|
|
92
92
|
onBrokenMarkdownImages: 'throw',
|
|
93
93
|
onUnusedMarkdownDirectives: 'warn',
|
|
94
94
|
};
|
|
95
|
-
|
|
95
|
+
const DEFAULT_MARKDOWN_MDX1COMPAT = {
|
|
96
96
|
comments: true,
|
|
97
97
|
admonitions: true,
|
|
98
98
|
headingIds: true,
|
|
99
99
|
};
|
|
100
|
-
|
|
100
|
+
const DEFAULT_MARKDOWN_CONFIG = {
|
|
101
101
|
// TODO Docusaurus v5: change this to "detect"?
|
|
102
102
|
// we probably need stable CommonMark support first
|
|
103
103
|
// see https://github.com/facebook/docusaurus/issues/9092
|
|
@@ -106,12 +106,12 @@ exports.DEFAULT_MARKDOWN_CONFIG = {
|
|
|
106
106
|
emoji: true,
|
|
107
107
|
preprocessor: undefined,
|
|
108
108
|
parseFrontMatter: utils_1.DEFAULT_PARSE_FRONT_MATTER,
|
|
109
|
-
mdx1Compat:
|
|
109
|
+
mdx1Compat: DEFAULT_MARKDOWN_MDX1COMPAT,
|
|
110
110
|
anchors: {
|
|
111
111
|
maintainCase: false,
|
|
112
112
|
},
|
|
113
113
|
remarkRehypeOptions: undefined,
|
|
114
|
-
hooks:
|
|
114
|
+
hooks: DEFAULT_MARKDOWN_HOOKS,
|
|
115
115
|
};
|
|
116
116
|
exports.DEFAULT_CONFIG = {
|
|
117
117
|
i18n: exports.DEFAULT_I18N_CONFIG,
|
|
@@ -135,7 +135,7 @@ exports.DEFAULT_CONFIG = {
|
|
|
135
135
|
tagline: '',
|
|
136
136
|
baseUrlIssueBanner: true,
|
|
137
137
|
staticDirectories: [utils_1.DEFAULT_STATIC_DIR_NAME],
|
|
138
|
-
markdown:
|
|
138
|
+
markdown: DEFAULT_MARKDOWN_CONFIG,
|
|
139
139
|
};
|
|
140
140
|
function createPluginSchema(theme) {
|
|
141
141
|
return utils_validation_1.Joi.alternatives()
|
|
@@ -449,7 +449,7 @@ function postProcessDocusaurusConfig(config) {
|
|
|
449
449
|
// Resolve mdx1Compat config based on the v4.mdx1CompatDisabledByDefault flag
|
|
450
450
|
// undefined means "not explicitly set by user"
|
|
451
451
|
const mdx1CompatDefault = !config.future.v4.mdx1CompatDisabledByDefault;
|
|
452
|
-
const mdx1CompatKeys = Object.keys(
|
|
452
|
+
const mdx1CompatKeys = Object.keys(DEFAULT_MARKDOWN_MDX1COMPAT);
|
|
453
453
|
for (const key of mdx1CompatKeys) {
|
|
454
454
|
(_a = config.markdown.mdx1Compat)[key] ?? (_a[key] = mdx1CompatDefault);
|
|
455
455
|
}
|
|
@@ -23,7 +23,6 @@ export declare function localizePluginTranslationFile({ localizationDir, plugin,
|
|
|
23
23
|
plugin: InitializedPlugin;
|
|
24
24
|
translationFile: TranslationFile;
|
|
25
25
|
}): Promise<TranslationFile>;
|
|
26
|
-
export declare function mergeCodeTranslations(codeTranslations: CodeTranslations[]): CodeTranslations;
|
|
27
26
|
export declare function loadPluginsDefaultCodeTranslationMessages(plugins: InitializedPlugin[]): Promise<CodeTranslations>;
|
|
28
27
|
export declare function getPluginsDefaultCodeTranslations({ plugins, }: {
|
|
29
28
|
plugins: LoadedPlugin[];
|
|
@@ -10,7 +10,6 @@ exports.readCodeTranslationFileContent = readCodeTranslationFileContent;
|
|
|
10
10
|
exports.writeCodeTranslations = writeCodeTranslations;
|
|
11
11
|
exports.writePluginTranslations = writePluginTranslations;
|
|
12
12
|
exports.localizePluginTranslationFile = localizePluginTranslationFile;
|
|
13
|
-
exports.mergeCodeTranslations = mergeCodeTranslations;
|
|
14
13
|
exports.loadPluginsDefaultCodeTranslationMessages = loadPluginsDefaultCodeTranslationMessages;
|
|
15
14
|
exports.getPluginsDefaultCodeTranslations = getPluginsDefaultCodeTranslations;
|
|
16
15
|
exports.applyDefaultCodeTranslations = applyDefaultCodeTranslations;
|
package/lib/ssg/ssgTemplate.d.ts
CHANGED
|
@@ -6,7 +6,7 @@
|
|
|
6
6
|
*/
|
|
7
7
|
import type { SSGParams } from './ssgParams';
|
|
8
8
|
import type { AppRenderResult } from '../common';
|
|
9
|
-
|
|
9
|
+
type SSGTemplateData = {
|
|
10
10
|
appHtml: string;
|
|
11
11
|
baseUrl: string;
|
|
12
12
|
htmlAttributes: string;
|
|
@@ -30,3 +30,4 @@ export declare function renderSSGTemplate({ params, result, ssgTemplate, }: {
|
|
|
30
30
|
export declare function renderHashRouterTemplate({ params, }: {
|
|
31
31
|
params: SSGParams;
|
|
32
32
|
}): Promise<string>;
|
|
33
|
+
export {};
|
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": "4.0.0-canary-
|
|
4
|
+
"version": "4.0.0-canary-6841",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"publishConfig": {
|
|
7
7
|
"access": "public"
|
|
@@ -33,14 +33,14 @@
|
|
|
33
33
|
"url": "https://github.com/facebook/docusaurus/issues"
|
|
34
34
|
},
|
|
35
35
|
"dependencies": {
|
|
36
|
-
"@docusaurus/babel": "4.0.0-canary-
|
|
37
|
-
"@docusaurus/bundler": "4.0.0-canary-
|
|
38
|
-
"@docusaurus/glob": "4.0.0-canary-
|
|
39
|
-
"@docusaurus/logger": "4.0.0-canary-
|
|
40
|
-
"@docusaurus/mdx-loader": "4.0.0-canary-
|
|
41
|
-
"@docusaurus/utils": "4.0.0-canary-
|
|
42
|
-
"@docusaurus/utils-common": "4.0.0-canary-
|
|
43
|
-
"@docusaurus/utils-validation": "4.0.0-canary-
|
|
36
|
+
"@docusaurus/babel": "4.0.0-canary-6841",
|
|
37
|
+
"@docusaurus/bundler": "4.0.0-canary-6841",
|
|
38
|
+
"@docusaurus/glob": "4.0.0-canary-6841",
|
|
39
|
+
"@docusaurus/logger": "4.0.0-canary-6841",
|
|
40
|
+
"@docusaurus/mdx-loader": "4.0.0-canary-6841",
|
|
41
|
+
"@docusaurus/utils": "4.0.0-canary-6841",
|
|
42
|
+
"@docusaurus/utils-common": "4.0.0-canary-6841",
|
|
43
|
+
"@docusaurus/utils-validation": "4.0.0-canary-6841",
|
|
44
44
|
"boxen": "^8.0.1",
|
|
45
45
|
"cli-table3": "^0.6.5",
|
|
46
46
|
"combine-promises": "^1.2.0",
|
|
@@ -76,8 +76,8 @@
|
|
|
76
76
|
"webpack-merge": "^6.0.1"
|
|
77
77
|
},
|
|
78
78
|
"devDependencies": {
|
|
79
|
-
"@docusaurus/module-type-aliases": "4.0.0-canary-
|
|
80
|
-
"@docusaurus/types": "4.0.0-canary-
|
|
79
|
+
"@docusaurus/module-type-aliases": "4.0.0-canary-6841",
|
|
80
|
+
"@docusaurus/types": "4.0.0-canary-6841",
|
|
81
81
|
"@total-typescript/shoehorn": "^0.1.2",
|
|
82
82
|
"@types/escape-html": "^1.0.4",
|
|
83
83
|
"@types/history": "^4.7.11",
|
|
@@ -88,10 +88,11 @@
|
|
|
88
88
|
"@types/update-notifier": "^6.0.8",
|
|
89
89
|
"@types/webpack-bundle-analyzer": "^4.7.0",
|
|
90
90
|
"@types/webpack-env": "^1.18.8",
|
|
91
|
-
"tree-node-cli": "^3.0.0"
|
|
91
|
+
"tree-node-cli": "^3.0.0",
|
|
92
|
+
"utility-types": "^3.11.0"
|
|
92
93
|
},
|
|
93
94
|
"peerDependencies": {
|
|
94
|
-
"@docusaurus/faster": "4.0.0-canary-
|
|
95
|
+
"@docusaurus/faster": "4.0.0-canary-6841",
|
|
95
96
|
"@mdx-js/react": "^3.1.1",
|
|
96
97
|
"react": "^19.3.0",
|
|
97
98
|
"react-dom": "^19.3.0"
|
|
@@ -104,5 +105,5 @@
|
|
|
104
105
|
"engines": {
|
|
105
106
|
"node": ">=24.21"
|
|
106
107
|
},
|
|
107
|
-
"gitHead": "
|
|
108
|
+
"gitHead": "6c97ad62ff58f7eda88392a0e33fcd982d826567"
|
|
108
109
|
}
|
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Copyright (c) Facebook, Inc. and its affiliates.
|
|
3
|
-
*
|
|
4
|
-
* This source code is licensed under the MIT license found in the
|
|
5
|
-
* LICENSE file in the root directory of this source tree.
|
|
6
|
-
*/
|
|
7
|
-
import React, { type ReactNode } from 'react';
|
|
8
|
-
export declare const Context: React.Context<boolean>;
|
|
9
|
-
export declare function BrowserContextProvider({ children, }: {
|
|
10
|
-
children: ReactNode;
|
|
11
|
-
}): ReactNode;
|
|
@@ -1,22 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Copyright (c) Facebook, Inc. and its affiliates.
|
|
3
|
-
*
|
|
4
|
-
* This source code is licensed under the MIT license found in the
|
|
5
|
-
* LICENSE file in the root directory of this source tree.
|
|
6
|
-
*/
|
|
7
|
-
import React, { useEffect, useState } from 'react';
|
|
8
|
-
// Encapsulate the logic to avoid React hydration problems
|
|
9
|
-
// See https://www.joshwcomeau.com/react/the-perils-of-rehydration/
|
|
10
|
-
// On first client-side render, we need to render exactly as the server rendered
|
|
11
|
-
// isBrowser is set to true only after a successful hydration
|
|
12
|
-
// Note, isBrowser is not part of useDocusaurusContext() for perf reasons
|
|
13
|
-
// Using useDocusaurusContext() (much more common need) should not trigger
|
|
14
|
-
// re-rendering after a successful hydration
|
|
15
|
-
export const Context = React.createContext(false);
|
|
16
|
-
export function BrowserContextProvider({ children, }) {
|
|
17
|
-
const [isBrowser, setIsBrowser] = useState(false);
|
|
18
|
-
useEffect(() => {
|
|
19
|
-
setIsBrowser(true);
|
|
20
|
-
}, []);
|
|
21
|
-
return <Context.Provider value={isBrowser}>{children}</Context.Provider>;
|
|
22
|
-
}
|