payload-canvas 0.5.1 → 0.5.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -3,7 +3,7 @@ import { jsx as _jsx } from "react/jsx-runtime";
3
3
  import { DefaultEditView, useConfig, useDocumentDrawerContext, useDocumentInfo } from '@payloadcms/ui';
4
4
  import { useRouter, useSearchParams } from 'next/navigation';
5
5
  import { useEffect } from 'react';
6
- import { builderViewPath, FORM_PARAM, opensInBuilder } from '../plugin/links.js';
6
+ import { builderOpening, builderViewPath, FORM_PARAM, opensInBuilder } from '../plugin/links.js';
7
7
  import { formChosen, rememberForm } from './formChoice.js';
8
8
  import './layoutField.scss';
9
9
  /**
@@ -35,7 +35,14 @@ export function DocumentEditView(props) {
35
35
  rememberForm(collectionSlug, id);
36
36
  }, [asked, hasId, collectionSlug, id, drawerSlug]);
37
37
  useEffect(() => {
38
- if (target)
38
+ if (!target)
39
+ return;
40
+ // A client navigation right after a full page load can lock React in a render loop in
41
+ // development: see `builderOpening`.
42
+ const loaded = performance.getEntriesByType('navigation')[0]?.name;
43
+ if (builderOpening(loaded, window.location.href) === 'page')
44
+ window.location.replace(target);
45
+ else
39
46
  router.replace(target);
40
47
  }, [target, router]);
41
48
  if (target) {
@@ -25,6 +25,20 @@ export declare function opensInBuilder(state: {
25
25
  inDrawer: boolean;
26
26
  formParam: string | null;
27
27
  }): boolean;
28
+ /**
29
+ * How the edit view goes on to the builder. `page`: a full page load, for an edit view that is the
30
+ * page the browser loaded (a typed or pasted URL, a new tab, a reload). `router`: a client
31
+ * navigation, for an edit view that Next's router opened (a link in the admin).
32
+ *
33
+ * A client navigation right after a full load can lock React in a render loop in development
34
+ * ("Maximum update depth exceeded" many times, the CPU busy). Strict Mode runs Payload's
35
+ * `CloseModalOnRouteChange` effect twice on mount, so it closes all modals once at idle priority.
36
+ * The navigation keeps React busy until the builder arrives, and then closes all modals again.
37
+ * From then on every render applies that close again and makes a new `modalState` object, and the
38
+ * effects that read it set state again, so the idle close never runs. A full page load gives
39
+ * the builder a fresh page. `loadedUrl` is the URL of the page load (Navigation Timing).
40
+ */
41
+ export declare function builderOpening(loadedUrl: string | null | undefined, currentUrl: string): 'page' | 'router';
28
42
  /** The public path of a document from the collection's `url` option. Null when it has none or it throws. */
29
43
  export declare function documentPath(url: ((doc: Record<string, unknown>) => string) | undefined, doc: Record<string, unknown>): string | null;
30
44
  /** The draft preview path from the collection's `admin.livePreview.url` or `admin.preview`. */
@@ -29,6 +29,29 @@ export function opensInBuilder(state) {
29
29
  return false;
30
30
  return formParam === null;
31
31
  }
32
+ /**
33
+ * How the edit view goes on to the builder. `page`: a full page load, for an edit view that is the
34
+ * page the browser loaded (a typed or pasted URL, a new tab, a reload). `router`: a client
35
+ * navigation, for an edit view that Next's router opened (a link in the admin).
36
+ *
37
+ * A client navigation right after a full load can lock React in a render loop in development
38
+ * ("Maximum update depth exceeded" many times, the CPU busy). Strict Mode runs Payload's
39
+ * `CloseModalOnRouteChange` effect twice on mount, so it closes all modals once at idle priority.
40
+ * The navigation keeps React busy until the builder arrives, and then closes all modals again.
41
+ * From then on every render applies that close again and makes a new `modalState` object, and the
42
+ * effects that read it set state again, so the idle close never runs. A full page load gives
43
+ * the builder a fresh page. `loadedUrl` is the URL of the page load (Navigation Timing).
44
+ */
45
+ export function builderOpening(loadedUrl, currentUrl) {
46
+ if (!loadedUrl)
47
+ return 'router';
48
+ try {
49
+ return new URL(loadedUrl).pathname === new URL(currentUrl).pathname ? 'page' : 'router';
50
+ }
51
+ catch {
52
+ return 'router';
53
+ }
54
+ }
32
55
  /** The public path of a document from the collection's `url` option. Null when it has none or it throws. */
33
56
  export function documentPath(url, doc) {
34
57
  if (!url)
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "payload-canvas",
3
- "version": "0.5.1",
3
+ "version": "0.5.2",
4
4
  "description": "Payload Canvas: a visual drag-and-drop website builder for Payload CMS 3. Nested layout blocks, Tailwind styling, sections, templates, live AI editing over MCP, and the React renderer for your site.",
5
5
  "keywords": [
6
6
  "payload",