Skip to content
JS Filters

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

NameTypeDescription
allowBooleanwhether the request runs, true by default
dataObjectthe preview component's props, state and internal handles

data has thirteen keys:

NameTypeDescription
propsObjectcurrent props of the preview component, including block, attributes and context
prevPropsObject | undefinedthe same props from the previous render, undefined on the first one
responseString | Object | nullcurrent preview content: markup on success, { error: true, response } after a failed request, null before the first one
setResponseFunctionwrites markup into the preview and fires the onChange action
isLoadingBooleanwhether a request is in flight
setIsLoadingFunctionstate setter behind the loading spinner
allowRenderBooleanfalse once the block answered lazy_block_no_render_callback
setAllowRenderFunctionstate setter for allowRender
isMountedRefObjectref whose current turns false when the block unmounts
currentFetchRequestObjectref holding the newest apiFetch promise, used to drop stale responses
postIdNumberid of the post being edited, 0 outside the post editor
fetchDataFunctionsends the request now
debouncedFetchDataFunctionsends 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.

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
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, and the markup it caches is chosen with lzb_pro/preload_blocks.

Was this article helpful?

Copyright © 2026 Lazy Blocks.