Skip to content

Commit

Permalink
support setting multiple modes
Browse files Browse the repository at this point in the history
  • Loading branch information
christian-bromann committed Aug 27, 2024
1 parent 9f407a8 commit 5ff5ee2
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 6 deletions.
4 changes: 2 additions & 2 deletions src/declarations/stencil-public-compiler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -957,10 +957,10 @@ export interface SerializeDocumentOptions extends HydrateDocumentOptions {
*/
fullDocument?: boolean;
/**
* Style mode to render the component in.
* Style modes to render the component in.
* @see https://stenciljs.com/docs/styling#style-modes
*/
mode?: ResolutionHandler;
modes?: ResolutionHandler[];
}

export interface HydrateFactoryOptions extends SerializeDocumentOptions {
Expand Down
4 changes: 2 additions & 2 deletions src/hydrate/runner/render.ts
Original file line number Diff line number Diff line change
Expand Up @@ -135,13 +135,13 @@ async function render(win: MockWindow, opts: HydrateFactoryOptions, results: Hyd
try {
await Promise.resolve(beforeHydrateFn(win.document));
return new Promise<HydrateResults>((resolve) => {
if (typeof opts.mode === 'function') {
if (Array.isArray(opts.modes)) {
/**
* Reset the mode resolution chain as we expect every `renderToString` call to render
* the components in new environment/document.
*/
modeResolutionChain.length = 0;
setMode(opts.mode);
opts.modes.forEach((mode) => setMode(mode));
}
return hydrateFactory(win, opts, results, afterHydrate, resolve);
});
Expand Down
4 changes: 2 additions & 2 deletions test/end-to-end/src/declarative-shadow-dom/test.e2e.ts
Original file line number Diff line number Diff line change
Expand Up @@ -296,7 +296,7 @@ describe('renderToString', () => {
const { html } = await renderToString('<prop-cmp first="Max" last="Mustermann"></prop-cmp>', {
fullDocument: false,
prettyHtml: true,
mode: () => 'ios',
modes: [() => 'ios'],
});
expect(html).toContain('<style>');
expect(html).toContain(';color:white;');
Expand All @@ -310,7 +310,7 @@ describe('renderToString', () => {
const { html } = await renderToString('<prop-cmp first="Max" last="Mustermann"></prop-cmp>', {
fullDocument: false,
prettyHtml: true,
mode: () => 'md',
modes: [() => 'md'],
});
expect(html).toContain(';color:black;');
const page = await newE2EPage({ html, url: 'https://stencil.com' });
Expand Down

0 comments on commit 5ff5ee2

Please sign in to comment.