Skip to content

Commit

Permalink
fix: revert "fix(ssr): infer the SSR mode in renderComponent" (#4837)
Browse files Browse the repository at this point in the history
This reverts commit d47c56c.
  • Loading branch information
nolanlawson authored Nov 12, 2024
1 parent f65e6bd commit 5bf5d91
Show file tree
Hide file tree
Showing 7 changed files with 31 additions and 18 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { renderComponent } from '@lwc/ssr-runtime';
import SlotUsage from '@lwc/perf-benchmarks-components/dist/ssr/benchmark/slotUsageComponent/slotUsageComponent.js';
import Store from '@lwc/perf-benchmarks-components/dist/ssr/benchmark/store/store.js';

const SSR_MODE = 'asyncYield';
const NUMBER_OF_ROWS = 5000;

benchmark(`ssr/slot/shadow/create/5k`, () => {
Expand All @@ -23,6 +24,6 @@ benchmark(`ssr/slot/shadow/create/5k`, () => {
titleOfComponentWithSlot: 'Component that receives a slot',
rowsOfComponentWithSlot: rowsOfComponentWithSlot,
};
return renderComponent('benchmark-slot-usage-component', SlotUsage, props);
return renderComponent('benchmark-slot-usage-component', SlotUsage, props, SSR_MODE);
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,20 @@ import { renderComponent } from '@lwc/ssr-runtime';
import Table from '@lwc/perf-benchmarks-components/dist/ssr/benchmark/table/table.js';
import Store from '@lwc/perf-benchmarks-components/dist/ssr/benchmark/store/store.js';

const SSR_MODE = 'asyncYield';

benchmark(`ssr/table-v2/render/10k`, () => {
run(() => {
const store = new Store();
store.runLots();

return renderComponent('benchmark-table', Table, {
rows: store.data,
});
return renderComponent(
'benchmark-table',
Table,
{
rows: store.data,
},
SSR_MODE
);
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,20 @@ import { renderComponent } from '@lwc/ssr-runtime';
import Table from '@lwc/perf-benchmarks-components/dist/ssr/benchmark/tableComponent/tableComponent.js';
import Store from '@lwc/perf-benchmarks-components/dist/ssr/benchmark/store/store.js';

const SSR_MODE = 'asyncYield';

benchmark(`ssr/table-component/render/10k`, () => {
run(() => {
const store = new Store();
store.runLots();

return renderComponent('benchmark-table', Table, {
rows: store.data,
});
return renderComponent(
'benchmark-table',
Table,
{
rows: store.data,
},
SSR_MODE
);
});
});
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
import { renderComponent } from '@lwc/ssr-runtime';

const SSR_MODE = 'asyncYield';

// Generic benchmark for styled components, SSR-flavored!
export function styledComponentSsrBenchmark(
name,
Expand All @@ -15,7 +17,8 @@ export function styledComponentSsrBenchmark(
await renderComponent(
isArray ? `styled-component${i}` : 'styled-component',
isArray ? componentOrComponents[i] : componentOrComponents,
{}
{},
SSR_MODE
);
}
});
Expand Down
3 changes: 2 additions & 1 deletion packages/@lwc/ssr-compiler/src/__tests__/fixtures.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,8 @@ describe.runIf(process.env.TEST_SSR_COMPILER).concurrent('fixtures', () => {
result = await serverSideRenderComponent(
module!.tagName,
module!.default,
config?.props ?? {}
config?.props ?? {},
SSR_MODE
);
} catch (err: any) {
return {
Expand Down
1 change: 0 additions & 1 deletion packages/@lwc/ssr-runtime/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,6 @@
},
"devDependencies": {
"@lwc/shared": "8.7.0",
"@lwc/ssr-compiler": "8.7.0",
"@lwc/engine-core": "8.7.0",
"observable-membrane": "2.0.0"
}
Expand Down
11 changes: 3 additions & 8 deletions packages/@lwc/ssr-runtime/src/render.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,14 @@
* SPDX-License-Identifier: MIT
* For full license text, see the LICENSE file in the repo root or https://opensource.org/licenses/MIT
*/
import { isGeneratorFunction, isAsyncFunction } from 'node:util/types';

import { mutationTracker } from './mutation-tracker';
import {
LightningElement,
LightningElementConstructor,
SYMBOL__GENERATE_MARKUP,
} from './lightning-element';
import type { Attributes, Properties } from './types';
import type { CompilationMode } from '@lwc/ssr-compiler';

const escapeAttrVal = (attrVal: string) =>
attrVal.replaceAll('&', '&').replaceAll('"', '"');
Expand Down Expand Up @@ -111,7 +110,8 @@ interface ComponentWithGenerateMarkup {
export async function serverSideRenderComponent(
tagName: string,
Component: GenerateMarkupFnVariants | ComponentWithGenerateMarkup,
props: Properties = {}
props: Properties = {},
mode: 'asyncYield' | 'async' | 'sync' = 'asyncYield'
): Promise<string> {
if (typeof tagName !== 'string') {
throw new Error(`tagName must be a string, found: ${tagName}`);
Expand All @@ -120,11 +120,6 @@ export async function serverSideRenderComponent(
// TODO [#4726]: remove `generateMarkup` export
const generateMarkup =
SYMBOL__GENERATE_MARKUP in Component ? Component[SYMBOL__GENERATE_MARKUP] : Component;
const mode: CompilationMode = isAsyncFunction(generateMarkup)
? isGeneratorFunction(generateMarkup)
? 'asyncYield'
: 'async'
: 'sync';

let markup = '';
const emit = (segment: string) => {
Expand Down

0 comments on commit 5bf5d91

Please sign in to comment.