| @@ -1,5 +1,4 @@ | ||
| 1 | -"use strict"; | |
| 2 | 1 | var wp; |
| 3 | 2 | (wp ||= {}).serverSideRender = (() => { |
| 4 | 3 | var __create = Object.create; |
| 5 | 4 | var __defProp = Object.defineProperty; |
| @@ -147,11 +146,9 @@ | ||
| 147 | 146 | style: restStyles |
| 148 | 147 | }; |
| 149 | 148 | } |
| 150 | 149 | function useServerSideRender(args) { |
| 151 | - const [response, setResponse] = (0, import_element.useState)({ | |
| 152 | - status: "idle" | |
| 153 | - }); | |
| 150 | + const [response, setResponse] = (0, import_element.useState)({ status: "idle" }); | |
| 154 | 151 | const shouldDebounceRef = (0, import_element.useRef)(false); |
| 155 | 152 | const { |
| 156 | 153 | attributes, |
| 157 | 154 | block, |
| @@ -159,9 +156,9 @@ | ||
| 159 | 156 | httpMethod = "GET", |
| 160 | 157 | urlQueryArgs |
| 161 | 158 | } = args; |
| 162 | 159 | let sanitizedAttributes = attributes && (0, import_blocks.__experimentalSanitizeBlockAttributes)(block, attributes); |
| 163 | - if (skipBlockSupportAttributes && sanitizedAttributes) { | |
| 160 | + if (skipBlockSupportAttributes) { | |
| 164 | 161 | sanitizedAttributes = removeBlockSupportAttributes(sanitizedAttributes); |
| 165 | 162 | } |
| 166 | 163 | const isPostRequest = "POST" === httpMethod; |
| 167 | 164 | const urlAttributes = isPostRequest ? null : sanitizedAttributes; |
| @@ -186,14 +183,14 @@ | ||
| 186 | 183 | status: "success", |
| 187 | 184 | content: res ? res.rendered : "" |
| 188 | 185 | }); |
| 189 | 186 | }).catch((error) => { |
| 190 | - if (error instanceof Error && error.name === "AbortError") { | |
| 187 | + if (error.name === "AbortError") { | |
| 191 | 188 | return; |
| 192 | 189 | } |
| 193 | 190 | setResponse({ |
| 194 | 191 | status: "error", |
| 195 | - error: error instanceof Error ? error.message : String(error) | |
| 192 | + error: error.message | |
| 196 | 193 | }); |
| 197 | 194 | }).finally(() => { |
| 198 | 195 | shouldDebounceRef.current = true; |
| 199 | 196 | }); |
| @@ -215,22 +212,17 @@ | ||
| 215 | 212 | var EMPTY_OBJECT = {}; |
| 216 | 213 | function DefaultEmptyResponsePlaceholder({ className }) { |
| 217 | 214 | return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_components.Placeholder, { className, children: (0, import_i18n.__)("Block rendered as empty.") }); |
| 218 | 215 | } |
| 219 | - function DefaultErrorResponsePlaceholder({ | |
| 220 | - message, | |
| 221 | - className | |
| 222 | - }) { | |
| 216 | + function DefaultErrorResponsePlaceholder({ message, className }) { | |
| 223 | 217 | const errorMessage = (0, import_i18n.sprintf)( |
| 224 | 218 | // translators: %s: error message describing the problem |
| 225 | 219 | (0, import_i18n.__)("Error loading block: %s"), |
| 226 | - message || (0, import_i18n.__)("Unknown error") | |
| 220 | + message | |
| 227 | 221 | ); |
| 228 | 222 | return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_components.Placeholder, { className, children: errorMessage }); |
| 229 | 223 | } |
| 230 | - function DefaultLoadingResponsePlaceholder({ | |
| 231 | - children | |
| 232 | - }) { | |
| 224 | + function DefaultLoadingResponsePlaceholder({ children }) { | |
| 233 | 225 | const [showLoader, setShowLoader] = (0, import_element2.useState)(false); |
| 234 | 226 | (0, import_element2.useEffect)(() => { |
| 235 | 227 | const timeout = setTimeout(() => { |
| 236 | 228 | setShowLoader(true); |
| @@ -269,13 +261,9 @@ | ||
| 269 | 261 | prevContentRef.current = content; |
| 270 | 262 | } |
| 271 | 263 | }, [content]); |
| 272 | 264 | if (status === "loading") { |
| 273 | - return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(LoadingResponsePlaceholder, { ...props, children: !!prevContentRef.current && /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_element2.RawHTML, { | |
| 274 | - className, | |
| 275 | - // eslint-disable-next-line react-hooks/refs | |
| 276 | - children: prevContentRef.current | |
| 277 | - }) }); | |
| 265 | + return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(LoadingResponsePlaceholder, { ...props, children: !!prevContentRef.current && /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_element2.RawHTML, { className, children: prevContentRef.current }) }); | |
| 278 | 266 | } |
| 279 | 267 | if (status === "success" && !content) { |
| 280 | 268 | return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(EmptyResponsePlaceholder, { ...props }); |
| 281 | 269 | } |
| @@ -281,9 +269,9 @@ | ||
| 281 | 269 | } |
| 282 | 270 | if (status === "error") { |
| 283 | 271 | return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(ErrorResponsePlaceholder, { message: error, ...props }); |
| 284 | 272 | } |
| 285 | - return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_element2.RawHTML, { className, children: content || "" }); | |
| 273 | + return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_element2.RawHTML, { className, children: content }); | |
| 286 | 274 | } |
| 287 | 275 | function ServerSideRenderWithPostId({ |
| 288 | 276 | urlQueryArgs = EMPTY_OBJECT, |
| 289 | 277 | ...props |
| @@ -288,10 +276,9 @@ | ||
| 288 | 276 | urlQueryArgs = EMPTY_OBJECT, |
| 289 | 277 | ...props |
| 290 | 278 | }) { |
| 291 | 279 | const currentPostId = (0, import_data.useSelect)((select) => { |
| 292 | - const editorStore = select("core/editor"); | |
| 293 | - const postId = editorStore?.getCurrentPostId?.(); | |
| 280 | + const postId = select("core/editor")?.getCurrentPostId(); | |
| 294 | 281 | return postId && typeof postId === "number" ? postId : null; |
| 295 | 282 | }, []); |
| 296 | 283 | const newUrlQueryArgs = (0, import_element2.useMemo)(() => { |
| 297 | 284 | if (!currentPostId) { |