-
Notifications
You must be signed in to change notification settings - Fork 9
Open
Description
Describe the bug
When compile the project in a static mode with local search enable, I encounter the following error:
ReferenceError: window is not defined
at LocalSearchProvider.get (node_modules/@diplodoc/client/build/server/app.js:462:9)
at LocalSearchProvider.link (node_modules/@diplodoc/client/build/server/app.js:403:30)
...YFM config:
allowHTML: true
staticContent: true
addSystemMeta: true
assetsPublicPath: /docs
search:
provider: local
confidence: phrased
tolerance: 2Problematic code
The error is caused by direct usage of the window object in the following lines:
- https://github.com/diplodoc-platform/client/blame/master/src/components/Search/provider/index.ts#L52
- https://github.com/diplodoc-platform/client/blame/master/src/components/Search/provider/index.ts#L56
Expected behavior
The code should not access the window object during SSR, as it is only available in the browser.
Possible solution
Add a check to ensure that the code referencing window only runs in the browser environment, e.g.:
if (typeof window !== 'undefined') {
// browser-specific code
}Reproduce at datalens docs repo:
datalens-tech/docs#13
Run command: npm run dev
Metadata
Metadata
Assignees
Labels
No labels