perf(ui): do not fetch doc permissions on autosave (#13477)
No need to re-fetch doc permissions during autosave. This will save us from making two additional client-side requests on every autosave interval, on top of the two existing requests needed to autosave and refresh form state. This _does_ mean that the UI will not fully reflect permissions again until you fully save, or until you navigating back, but that has always been the behavior anyway (until #13416). Maybe we can find another solution for this in the future, or otherwise consider this to be expected behavior. --- - To see the specific tasks where the Asana app for GitHub is being used, see below: - https://app.asana.com/0/0/1211094073049052
This commit is contained in:
@@ -18,7 +18,6 @@ export const AutosavePostsCollection: CollectionConfig = {
|
||||
hooks: {
|
||||
beforeChange: [({ data }) => data?.title],
|
||||
},
|
||||
label: 'Computed Title',
|
||||
},
|
||||
],
|
||||
versions: {
|
||||
|
||||
@@ -10,6 +10,7 @@ import { addArrayRowAsync, removeArrayRow } from 'helpers/e2e/fields/array/index
|
||||
import { addBlock } from 'helpers/e2e/fields/blocks/index.js'
|
||||
import { waitForAutoSaveToRunAndComplete } from 'helpers/e2e/waitForAutoSaveToRunAndComplete.js'
|
||||
import * as path from 'path'
|
||||
import { wait } from 'payload/shared'
|
||||
import { fileURLToPath } from 'url'
|
||||
|
||||
import type { Config, Post } from './payload-types.js'
|
||||
@@ -330,6 +331,94 @@ test.describe('Form State', () => {
|
||||
).toHaveValue('This is a computed value.')
|
||||
})
|
||||
|
||||
test('should fetch new doc permissions after save', async () => {
|
||||
const doc = await createPost({ title: 'Initial Title' })
|
||||
await page.goto(postsUrl.edit(doc.id))
|
||||
const titleField = page.locator('#field-title')
|
||||
await expect(titleField).toBeEnabled()
|
||||
|
||||
await assertNetworkRequests(
|
||||
page,
|
||||
`${serverURL}/api/posts/access/${doc.id}`,
|
||||
async () => {
|
||||
await titleField.fill('Updated Title')
|
||||
await wait(500)
|
||||
await page.click('#action-save', { delay: 100 })
|
||||
},
|
||||
{
|
||||
allowedNumberOfRequests: 2,
|
||||
minimumNumberOfRequests: 2,
|
||||
timeout: 3000,
|
||||
},
|
||||
)
|
||||
|
||||
await assertNetworkRequests(
|
||||
page,
|
||||
`${serverURL}/api/posts/access/${doc.id}`,
|
||||
async () => {
|
||||
await titleField.fill('Updated Title 2')
|
||||
await wait(500)
|
||||
await page.click('#action-save', { delay: 100 })
|
||||
},
|
||||
{
|
||||
minimumNumberOfRequests: 2,
|
||||
allowedNumberOfRequests: 2,
|
||||
timeout: 3000,
|
||||
},
|
||||
)
|
||||
})
|
||||
|
||||
test('autosave - should not fetch new doc permissions on every autosave', async () => {
|
||||
const doc = await payload.create({
|
||||
collection: autosavePostsSlug,
|
||||
data: {
|
||||
title: 'Initial Title',
|
||||
},
|
||||
})
|
||||
|
||||
await page.goto(autosavePostsUrl.edit(doc.id))
|
||||
const titleField = page.locator('#field-title')
|
||||
await expect(titleField).toBeEnabled()
|
||||
|
||||
await assertNetworkRequests(
|
||||
page,
|
||||
`${serverURL}/api/${autosavePostsSlug}/access/${doc.id}`,
|
||||
async () => {
|
||||
await titleField.fill('Updated Title')
|
||||
},
|
||||
{
|
||||
allowedNumberOfRequests: 0,
|
||||
timeout: 3000,
|
||||
},
|
||||
)
|
||||
|
||||
await assertNetworkRequests(
|
||||
page,
|
||||
`${serverURL}/api/${autosavePostsSlug}/access/${doc.id}`,
|
||||
async () => {
|
||||
await titleField.fill('Updated Title Again')
|
||||
},
|
||||
{
|
||||
allowedNumberOfRequests: 0,
|
||||
timeout: 3000,
|
||||
},
|
||||
)
|
||||
|
||||
// save manually and ensure the permissions are fetched again
|
||||
await assertNetworkRequests(
|
||||
page,
|
||||
`${serverURL}/api/${autosavePostsSlug}/access/${doc.id}`,
|
||||
async () => {
|
||||
await page.click('#action-save', { delay: 100 })
|
||||
},
|
||||
{
|
||||
allowedNumberOfRequests: 2,
|
||||
minimumNumberOfRequests: 2,
|
||||
timeout: 3000,
|
||||
},
|
||||
)
|
||||
})
|
||||
|
||||
test('autosave - should render computed values after autosave', async () => {
|
||||
await page.goto(autosavePostsUrl.create)
|
||||
const titleField = page.locator('#field-title')
|
||||
|
||||
Reference in New Issue
Block a user