docs: add jsdoc for IS_BROWSER (#1991)
This commit is contained in:
@@ -183,7 +183,8 @@ An error occurred during route handling or page rendering. ReferenceError: Event
|
|||||||
....
|
....
|
||||||
```
|
```
|
||||||
|
|
||||||
Use the `IS_BROWSER` flag as a guard to fix the issue:
|
Use the [`IS_BROWSER`](https://deno.land/x/fresh/runtime.ts?doc=&s=IS_BROWSER)
|
||||||
|
flag as a guard to fix the issue:
|
||||||
|
|
||||||
```tsx islands/my-island.tsx
|
```tsx islands/my-island.tsx
|
||||||
import { IS_BROWSER } from "$fresh/runtime.ts";
|
import { IS_BROWSER } from "$fresh/runtime.ts";
|
||||||
|
|||||||
@@ -4,6 +4,22 @@ import { BUILD_ID } from "./build_id.ts";
|
|||||||
export const INTERNAL_PREFIX = "/_frsh";
|
export const INTERNAL_PREFIX = "/_frsh";
|
||||||
export const ASSET_CACHE_BUST_KEY = "__frsh_c";
|
export const ASSET_CACHE_BUST_KEY = "__frsh_c";
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns true when the current runtime is the browser and false otherwise. This is used for guard runtime-dependent code.
|
||||||
|
* Shorthand for the following:
|
||||||
|
* `typeof document !== "undefined"`
|
||||||
|
*
|
||||||
|
* @example
|
||||||
|
* ```
|
||||||
|
* if (IS_BROWSER) {
|
||||||
|
* alert('This is running in the browser!');
|
||||||
|
* } else {
|
||||||
|
* console.log('This code is running on the server, no access to window or alert');
|
||||||
|
* }
|
||||||
|
* ```
|
||||||
|
*
|
||||||
|
* Without this guard, alert pauses the server until return is pressed in the console.
|
||||||
|
*/
|
||||||
export const IS_BROWSER = typeof document !== "undefined";
|
export const IS_BROWSER = typeof document !== "undefined";
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
Reference in New Issue
Block a user