@@ -193,24 +193,47 @@ interface ComponentWithGenerateMarkup extends LightningElementConstructor {
193
193
194
194
export class RenderContext {
195
195
styleDedupeIsEnabled : boolean ;
196
- stylesheetToId = new WeakMap < Stylesheet , string > ( ) ;
197
196
styleDedupePrefix : string ;
197
+ stylesheetToId = new WeakMap < Stylesheet , string > ( ) ;
198
198
nextId = 0 ;
199
199
200
- constructor ( styleDedupePrefix : string , styleDedupeIsEnabled : boolean ) {
201
- this . styleDedupeIsEnabled = styleDedupeIsEnabled ;
202
- this . styleDedupePrefix = styleDedupePrefix ;
200
+ constructor ( styleDedupe : string | boolean ) {
201
+ if ( styleDedupe || styleDedupe === '' ) {
202
+ this . styleDedupePrefix = typeof styleDedupe === 'string' ? styleDedupe : '' ;
203
+ this . styleDedupeIsEnabled = true ;
204
+ } else {
205
+ this . styleDedupePrefix = '' ;
206
+ this . styleDedupeIsEnabled = false ;
207
+ }
203
208
}
204
209
}
205
210
211
+ /**
212
+ * Create a string representing an LWC component for server-side rendering.
213
+ * @param tagName The HTML tag name of the component
214
+ * @param Component The `LightningElement` component constructor
215
+ * @param props HTML attributes to provide for the root component
216
+ * @param styleDedupe Provide a string key or `true` to enable style deduping via the `<lwc-style>`
217
+ * helper. The key is used to avoid collisions of global IDs.
218
+ * @param mode SSR render mode. Can be 'sync', 'async' or 'asyncYield'. Must match the render mode
219
+ * used to compile your component.
220
+ * @returns String representation of the component
221
+ */
206
222
export async function serverSideRenderComponent (
207
223
tagName : string ,
208
224
Component : ComponentWithGenerateMarkup ,
209
225
props : Properties = { } ,
210
- styleDedupePrefix = '' ,
211
- styleDedupeIsEnabled = false ,
226
+ styleDedupe : string | boolean = false ,
212
227
mode : CompilationMode = DEFAULT_SSR_MODE
213
228
) : Promise < string > {
229
+ // TODO [#5309]: Remove this warning after a single release
230
+ if ( process . env . NODE_ENV !== 'production' ) {
231
+ if ( arguments . length === 6 || ! [ 'sync' , 'async' , 'asyncYield' ] . includes ( mode ) ) {
232
+ throw new Error (
233
+ "The signature for @lwc/ssr-runtime's `renderComponent` has changed. There is now only one parameter for style dedupe."
234
+ ) ;
235
+ }
236
+ }
214
237
if ( typeof tagName !== 'string' ) {
215
238
throw new Error ( `tagName must be a string, found: ${ tagName } ` ) ;
216
239
}
@@ -222,7 +245,7 @@ export async function serverSideRenderComponent(
222
245
markup += segment ;
223
246
} ;
224
247
225
- emit . cxt = new RenderContext ( styleDedupePrefix , styleDedupeIsEnabled ) ;
248
+ emit . cxt = new RenderContext ( styleDedupe ) ;
226
249
227
250
if ( ! generateMarkup ) {
228
251
// If a non-component is accidentally provided, render an empty template
0 commit comments