Repository navigation
feat(next): regenerate live preview url on save - #13631
Conversation
📦 esbuild Bundle Analysis for payloadThis analysis was generated by esbuild-bundle-analyzer. 🤖
Largest pathsThese visualization shows top 20 largest paths in the bundle.Meta file: packages/next/meta_index.json, Out file: esbuild/index.js
Meta file: packages/payload/meta_index.json, Out file: esbuild/index.js
Meta file: packages/payload/meta_shared.json, Out file: esbuild/exports/shared.js
Meta file: packages/richtext-lexical/meta_client.json, Out file: esbuild/exports/client_optimized/index.js
Meta file: packages/ui/meta_client.json, Out file: esbuild/exports/client_optimized/index.js
Meta file: packages/ui/meta_shared.json, Out file: esbuild/exports/shared_optimized/index.js
DetailsNext to the size is how much the size has increased or decreased compared with the base branch of this PR.
|
|
i worked around this a different way whereby we support a route for this change would be helpful to not need the |
|
@roastlechon that works! Good temporary solution, thanks for sharing. This PR will prevent you from having to do any customization in your front-end and aligns more closely to the expected behavior. |
|
Any update on this one? |
@PP-Tom this is done and will go out in the next release |
|
🚀 This is included in version v3.57.0 |
|
This is huge! I just refactored my whole preview setup with separate id-based /preview/[slug] lookups to prevent this 404'ing when changing the slug. Thanks. |
As of #13631, statically defined live preview URLs become corrupt after the first save. For example, if you define your URL as a string like this: ```ts import type { CollectionConfig } from 'payload' const MyCollection: CollectionConfig = { // ... admin: { livePreview: { url: '/hello-world' } } } ``` On initial load, the iframe's src will evaluate to `.../hello-world` as expected, but from the first save onward, the url becomes `.../undefined`. This is because for statically defined URLs, the `livePreviewURL` property does not exist on the response. Despite this, we set it into state as undefined. This is true for both collections and globals. Initially reported on Discord here: https://discord.com/channels/967097582721572934/967097582721572937/1421166976113442847 --- - To see the specific tasks where the Asana app for GitHub is being used, see below: - https://app.asana.com/0/0/1211478736160152
|
Hi, can you check this issue pls: #14033 I think that has something to do with this PR. Thanks a lot :) |
Closes #12785.
Although your live preview URL can be dynamic based on document data, it is never recalculated after initial mount. This means if your URL is dependent of document data that was just changed, such as a "slug" field, the URL of the iframe does not reflect that change as expected until the window is refreshed or you navigate back.
This also means that server-side live preview will crash when your front-end attempts to query using a slug that no longer exists. Here's the general flow: slug changes, autosave runs, iframe refreshes (url has old slug), 404.
Now, we execute your live preview function on submit within form state, and the window responds to the new URL as expected, refreshing itself without losing its connection.
Here's the result:
after.mp4