PluginProbe
Gutenberg / trunk
Gutenberg vtrunk
24.1.0 24.0.0 23.9.1 23.9.0 23.8.0 23.7.2 23.7.1 23.7.0 23.6.1 23.6.2 23.6.0 23.5.3 23.5.2 23.5.1 23.5.0 23.4.0 23.3.2 23.3.1 23.3.0 23.2.0 23.2.1 23.2.2 23.1.1 23.1.0 23.0.1 All 404 releases
← All changes | build/scripts/server-side-render/index.js +27 -11 23.0.1 → trunk View file →
@@ -1,4 +1,6 @@
1 +(function() {
2 +"use strict";
1 3 var wp;
2 4 (wp ||= {}).serverSideRender = (() => {
3 5 var __create = Object.create;
4 6 var __defProp = Object.defineProperty;
@@ -146,9 +148,11 @@
146 148 style: restStyles
147 149 };
148 150 }
149 151 function useServerSideRender(args) {
150 - const [response, setResponse] = (0, import_element.useState)({ status: "idle" });
152 + const [response, setResponse] = (0, import_element.useState)({
153 + status: "idle"
154 + });
151 155 const shouldDebounceRef = (0, import_element.useRef)(false);
152 156 const {
153 157 attributes,
154 158 block,
@@ -155,10 +159,10 @@
155 159 skipBlockSupportAttributes = false,
156 160 httpMethod = "GET",
157 161 urlQueryArgs
158 162 } = args;
159 - let sanitizedAttributes = attributes && (0, import_blocks.__experimentalSanitizeBlockAttributes)(block, attributes);
160 - if (skipBlockSupportAttributes) {
163 + let sanitizedAttributes = attributes && (0, import_blocks.sanitizeBlockAttributes)(block, attributes);
164 + if (skipBlockSupportAttributes && sanitizedAttributes) {
161 165 sanitizedAttributes = removeBlockSupportAttributes(sanitizedAttributes);
162 166 }
163 167 const isPostRequest = "POST" === httpMethod;
164 168 const urlAttributes = isPostRequest ? null : sanitizedAttributes;
@@ -183,14 +187,14 @@
183 187 status: "success",
184 188 content: res ? res.rendered : ""
185 189 });
186 190 }).catch((error) => {
187 - if (error.name === "AbortError") {
191 + if (error instanceof Error && error.name === "AbortError") {
188 192 return;
189 193 }
190 194 setResponse({
191 195 status: "error",
192 - error: error.message
196 + error: error instanceof Error ? error.message : String(error)
193 197 });
194 198 }).finally(() => {
195 199 shouldDebounceRef.current = true;
196 200 });
@@ -212,17 +216,22 @@
212 216 var EMPTY_OBJECT = {};
213 217 function DefaultEmptyResponsePlaceholder({ className }) {
214 218 return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_components.Placeholder, { className, children: (0, import_i18n.__)("Block rendered as empty.") });
215 219 }
216 - function DefaultErrorResponsePlaceholder({ message, className }) {
220 + function DefaultErrorResponsePlaceholder({
221 + message,
222 + className
223 + }) {
217 224 const errorMessage = (0, import_i18n.sprintf)(
218 225 // translators: %s: error message describing the problem
219 226 (0, import_i18n.__)("Error loading block: %s"),
220 - message
227 + message || (0, import_i18n.__)("Unknown error")
221 228 );
222 229 return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_components.Placeholder, { className, children: errorMessage });
223 230 }
224 - function DefaultLoadingResponsePlaceholder({ children }) {
231 + function DefaultLoadingResponsePlaceholder({
232 + children
233 + }) {
225 234 const [showLoader, setShowLoader] = (0, import_element2.useState)(false);
226 235 (0, import_element2.useEffect)(() => {
227 236 const timeout = setTimeout(() => {
228 237 setShowLoader(true);
@@ -261,9 +270,13 @@
261 270 prevContentRef.current = content;
262 271 }
263 272 }, [content]);
264 273 if (status === "loading") {
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 }) });
274 + return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(LoadingResponsePlaceholder, { ...props, children: !!prevContentRef.current && /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_element2.RawHTML, {
275 + className,
276 + // eslint-disable-next-line react-hooks/refs
277 + children: prevContentRef.current
278 + }) });
266 279 }
267 280 if (status === "success" && !content) {
268 281 return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(EmptyResponsePlaceholder, { ...props });
269 282 }
@@ -269,9 +282,9 @@
269 282 }
270 283 if (status === "error") {
271 284 return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(ErrorResponsePlaceholder, { message: error, ...props });
272 285 }
273 - return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_element2.RawHTML, { className, children: content });
286 + return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_element2.RawHTML, { className, children: content || "" });
274 287 }
275 288 function ServerSideRenderWithPostId({
276 289 urlQueryArgs = EMPTY_OBJECT,
277 290 ...props
@@ -276,9 +289,10 @@
276 289 urlQueryArgs = EMPTY_OBJECT,
277 290 ...props
278 291 }) {
279 292 const currentPostId = (0, import_data.useSelect)((select) => {
280 - const postId = select("core/editor")?.getCurrentPostId();
293 + const editorStore = select("core/editor");
294 + const postId = editorStore?.getCurrentPostId?.();
281 295 return postId && typeof postId === "number" ? postId : null;
282 296 }, []);
283 297 const newUrlQueryArgs = (0, import_element2.useMemo)(() => {
284 298 if (!currentPostId) {
@@ -299,5 +313,7 @@
299 313 var index_default = ServerSideRenderCompat;
300 314 return __toCommonJS(index_exports);
301 315 })();
302 316 if (typeof wp.serverSideRender === 'object' && wp.serverSideRender.default) { wp.serverSideRender = wp.serverSideRender.default; }
317 +(window.wp ||= {}).serverSideRender = wp.serverSideRender;
318 +})();
303 319 //# sourceMappingURL=index.js.map