---
title: "lzb.components.PreviewServerCallback.allowFetch"
description: "JS filter `lzb.components.PreviewServerCallback.allowFetch` of the Lazy Blocks WordPress plugin."
url: "https://www.lazyblocks.com/docs/js-filters/lzb-components-previewservercallback-allowfetch/"
lastUpdated: 2026-09-09
source: "js-filters/lzb-components-previewservercallback-allowfetch.mdx"
---
# lzb.components.PreviewServerCallback.allowFetch

Runs before the editor preview posts to `lazy-blocks/v1/block-render`. Return a falsy value to skip that request, which is how the Pro blocks preloading feature fills the first preview from markup the editor page already carries instead of asking the server again.

## Attributes

| Name    | Type        | Description                                               |
| ------- | ----------- | --------------------------------------------------------- |
| `allow` | **Boolean** | whether the request runs, `true` by default               |
| `data`  | **Object**  | the preview component's props, state and internal handles |

`data` has thirteen keys:

| Name                  | Type                         | Description                                                                                                                 |
| --------------------- | ---------------------------- | --------------------------------------------------------------------------------------------------------------------------- |
| `props`               | **Object**                   | current props of the preview component, including `block`, `attributes` and `context`                                       |
| `prevProps`           | **Object \| undefined**      | the same props from the previous render, `undefined` on the first one                                                       |
| `response`            | **String \| Object \| null** | current preview content: markup on success, `{ error: true, response }` after a failed request, `null` before the first one |
| `setResponse`         | **Function**                 | writes markup into the preview and fires the `onChange` action                                                              |
| `isLoading`           | **Boolean**                  | whether a request is in flight                                                                                              |
| `setIsLoading`        | **Function**                 | state setter behind the loading spinner                                                                                     |
| `allowRender`         | **Boolean**                  | `false` once the block answered `lazy_block_no_render_callback`                                                             |
| `setAllowRender`      | **Function**                 | state setter for `allowRender`                                                                                              |
| `isMountedRef`        | **Object**                   | ref whose `current` turns `false` when the block unmounts                                                                   |
| `currentFetchRequest` | **Object**                   | ref holding the newest `apiFetch` promise, used to drop stale responses                                                     |
| `postId`              | **Number**                   | id of the post being edited, `0` outside the post editor                                                                    |
| `fetchData`           | **Function**                 | sends the request now                                                                                                       |
| `debouncedFetchData`  | **Function**                 | sends the request 500ms from now, cancelling any pending call                                                               |

`prevProps` is how a handler tells the first render from the rest. `setResponse` is not the raw state setter, it is the same wrapper the fetch success path uses, so calling it both paints the preview and fires [lzb.components.PreviewServerCallback.onChange](https://www.lazyblocks.com/docs/js-actions/lzb-components-previewservercallback-onchange/).

The filter sits in an effect with no dependency list, so it runs on every render of the preview, including the renders where nothing would have been fetched anyway. Keep the handler cheap.

## Usage

```js title="JS"
wp.hooks.addFilter(
  "lzb.components.PreviewServerCallback.allowFetch",
  "my.custom.namespace",
  function (allow, { props, prevProps, setResponse }) {
    // Hydrate on the first render only, and let every later one fetch.
    if (prevProps !== undefined) {
      return allow;
    }

    const blockId = props?.attributes?.blockId;
    const cached = blockId && window.myPreloadedBlocks?.[blockId];

    if (typeof cached === "string" && cached.length) {
      setResponse(cached);
      return false;
    }

    return allow;
  },
);
```

Returning falsy without calling `setResponse` leaves the preview blank until an attribute or context change re-runs the effect, so a handler that blocks the request owns the job of putting markup in. The Pro version registers this filter for you as part of [editor preloading](https://www.lazyblocks.com/docs/performance/), and the markup it caches is chosen with [lzb_pro/preload_blocks](https://www.lazyblocks.com/docs/php-filters/lzb_pro-preload_blocks/).

## Documentation Index
> Fetch the complete documentation index at: https://www.lazyblocks.com/llms.txt
> Fetch every page in a single file at: https://www.lazyblocks.com/llms-full.txt
