@@ -49,7 +49,7 @@ export const renderDocument = async ({
49
49
} > => {
50
50
const {
51
51
collectionConfig,
52
- docID : id ,
52
+ docID : idFromArgs ,
53
53
globalConfig,
54
54
locale,
55
55
permissions,
@@ -72,7 +72,7 @@ export const renderDocument = async ({
72
72
const segments = Array . isArray ( params ?. segments ) ? params . segments : [ ]
73
73
const collectionSlug = collectionConfig ?. slug || undefined
74
74
const globalSlug = globalConfig ?. slug || undefined
75
- const isEditing = getIsEditing ( { id, collectionSlug, globalSlug } )
75
+ let isEditing = getIsEditing ( { id : idFromArgs , collectionSlug, globalSlug } )
76
76
77
77
let RootViewOverride : PayloadComponent
78
78
let CustomView : ViewFromConfig < ServerSideEditViewProps >
@@ -82,10 +82,10 @@ export const renderDocument = async ({
82
82
let apiURL : string
83
83
84
84
// Fetch the doc required for the view
85
- const doc =
85
+ let doc =
86
86
initialData ||
87
87
( await getDocumentData ( {
88
- id,
88
+ id : idFromArgs ,
89
89
collectionSlug,
90
90
globalSlug,
91
91
locale,
@@ -104,7 +104,7 @@ export const renderDocument = async ({
104
104
] = await Promise . all ( [
105
105
// Get document preferences
106
106
getDocPreferences ( {
107
- id,
107
+ id : idFromArgs ,
108
108
collectionSlug,
109
109
globalSlug,
110
110
payload,
@@ -113,7 +113,7 @@ export const renderDocument = async ({
113
113
114
114
// Get permissions
115
115
getDocumentPermissions ( {
116
- id,
116
+ id : idFromArgs ,
117
117
collectionConfig,
118
118
data : doc ,
119
119
globalConfig,
@@ -122,7 +122,7 @@ export const renderDocument = async ({
122
122
123
123
// Fetch document lock state
124
124
getIsLocked ( {
125
- id,
125
+ id : idFromArgs ,
126
126
collectionConfig,
127
127
globalConfig,
128
128
isEditing,
@@ -135,7 +135,7 @@ export const renderDocument = async ({
135
135
{ state : formState } ,
136
136
] = await Promise . all ( [
137
137
getVersions ( {
138
- id,
138
+ id : idFromArgs ,
139
139
collectionConfig,
140
140
docPermissions,
141
141
globalConfig,
@@ -144,15 +144,15 @@ export const renderDocument = async ({
144
144
user,
145
145
} ) ,
146
146
buildFormState ( {
147
- id,
147
+ id : idFromArgs ,
148
148
collectionSlug,
149
149
data : doc ,
150
150
docPermissions,
151
151
docPreferences,
152
152
fallbackLocale : false ,
153
153
globalSlug,
154
154
locale : locale ?. code ,
155
- operation : ( collectionSlug && id ) || globalSlug ? 'update' : 'create' ,
155
+ operation : ( collectionSlug && idFromArgs ) || globalSlug ? 'update' : 'create' ,
156
156
renderAllFields : true ,
157
157
req,
158
158
schemaPath : collectionSlug || globalSlug ,
@@ -187,7 +187,7 @@ export const renderDocument = async ({
187
187
188
188
const apiQueryParams = `?${ params . toString ( ) } `
189
189
190
- apiURL = `${ serverURL } ${ apiRoute } /${ collectionSlug } /${ id } ${ apiQueryParams } `
190
+ apiURL = `${ serverURL } ${ apiRoute } /${ collectionSlug } /${ idFromArgs } ${ apiQueryParams } `
191
191
192
192
RootViewOverride =
193
193
collectionConfig ?. admin ?. components ?. views ?. edit ?. root &&
@@ -274,8 +274,10 @@ export const renderDocument = async ({
274
274
const validateDraftData =
275
275
collectionConfig ?. versions ?. drafts && collectionConfig ?. versions ?. drafts ?. validate
276
276
277
- if ( shouldAutosave && ! validateDraftData && ! id && collectionSlug ) {
278
- const doc = await payload . create ( {
277
+ let id = idFromArgs
278
+
279
+ if ( shouldAutosave && ! validateDraftData && ! idFromArgs && collectionSlug ) {
280
+ doc = await payload . create ( {
279
281
collection : collectionSlug ,
280
282
data : initialData || { } ,
281
283
depth : 0 ,
@@ -287,12 +289,18 @@ export const renderDocument = async ({
287
289
} )
288
290
289
291
if ( doc ?. id ) {
290
- const redirectURL = formatAdminURL ( {
291
- adminRoute,
292
- path : `/collections/${ collectionSlug } /${ doc . id } ` ,
293
- serverURL,
294
- } )
295
- redirect ( redirectURL )
292
+ id = doc . id
293
+ isEditing = getIsEditing ( { id : doc . id , collectionSlug, globalSlug } )
294
+
295
+ if ( ! drawerSlug ) {
296
+ const redirectURL = formatAdminURL ( {
297
+ adminRoute,
298
+ path : `/collections/${ collectionSlug } /${ doc . id } ` ,
299
+ serverURL,
300
+ } )
301
+
302
+ redirect ( redirectURL )
303
+ }
296
304
} else {
297
305
throw new Error ( 'not-found' )
298
306
}
0 commit comments