Skip to content

Commit 2f38290

Browse files
authored
fix(richtext-lexical): richtext editor features overriding other editor features props if multiple editors in one document (#7758)
Example: richText editor 1 and 2 both have UploadFeature. richText editor 1 calls UploadFeature() with custom fields, richText editor 2 calls UploadFeature() with NO custom fields. Before this PR, richText editor 1 would not have had any custom fields, as richText editor 2 will override the feature object (specifically its props).
1 parent a526c7b commit 2f38290

File tree

2 files changed

+15
-4
lines changed

2 files changed

+15
-4
lines changed

packages/richtext-lexical/src/utilities/createClientFeature.ts

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -58,8 +58,16 @@ export const createClientFeature: <
5858
return toReturn
5959
}
6060
} else {
61-
;(feature as ClientFeature<any>).sanitizedClientFeatureProps = props
62-
featureProviderClient.feature = feature as ClientFeature<any>
61+
// We have to spread feature here! Otherwise, if the arg of createClientFeature is not a function, and 2
62+
// richText editors have the same feature (even if both call it, e.g. both call UploadFeature()),
63+
// the second richText editor here will override sanitizedClientFeatureProps of the first feature, as both richText
64+
// editor features share the same reference to the feature object.
65+
// Example: richText editor 1 and 2 both have UploadFeature. richText editor 1 calls UploadFeature() with custom fields,
66+
// richText editor 2 calls UploadFeature() with NO custom fields. If we don't spread feature here, richText editor 1
67+
// will not have any custom fields, as richText editor 2 will override the feature object.
68+
const newFeature: ClientFeature<any> = { ...feature }
69+
newFeature.sanitizedClientFeatureProps = props
70+
featureProviderClient.feature = newFeature
6371
}
6472
return featureProviderClient as FeatureProviderClient<any, any>
6573
}

packages/richtext-lexical/src/utilities/createServerFeature.ts

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -75,8 +75,11 @@ export const createServerFeature: <
7575
return toReturn
7676
}
7777
} else {
78-
;(feature as ServerFeature<any, any>).sanitizedServerFeatureProps = props
79-
featureProviderServer.feature = feature as ServerFeature<any, any>
78+
// For explanation why we have to spread feature, see createClientFeature.ts
79+
const newFeature: ServerFeature<any, any> = { ...feature }
80+
81+
newFeature.sanitizedServerFeatureProps = props
82+
featureProviderServer.feature = newFeature
8083
}
8184
return featureProviderServer as FeatureProviderServer<any, any, any>
8285
}

0 commit comments

Comments
 (0)