Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 32 additions & 1 deletion packages/docs/src/routes/api/qwik/api.json
Original file line number Diff line number Diff line change
Expand Up @@ -2105,7 +2105,7 @@
}
],
"kind": "TypeAlias",
"content": "```typescript\nexport type SSRStreamChildren = AsyncGenerator<JSXChildren, void, any> | ((stream: StreamWriter) => Promise<void>) | (() => AsyncGenerator<JSXChildren, void, any>);\n```\n**References:** [JSXChildren](#jsxchildren)",
"content": "```typescript\nexport type SSRStreamChildren = AsyncGenerator<JSXChildren, void, any> | ((stream: SSRStreamWriter) => Promise<void>) | (() => AsyncGenerator<JSXChildren, void, any>);\n```\n**References:** [JSXChildren](#jsxchildren)<!-- -->, [SSRStreamWriter](#ssrstreamwriter)",
"editUrl": "https://github.com/QwikDev/qwik/tree/main/packages/qwik/src/core/shared/jsx/utils.public.ts",
"mdFile": "core.ssrstreamchildren.md"
},
Expand All @@ -2123,6 +2123,20 @@
"editUrl": "https://github.com/QwikDev/qwik/tree/main/packages/qwik/src/core/shared/jsx/utils.public.ts",
"mdFile": "core.ssrstreamprops.md"
},
{
"name": "SSRStreamWriter",
"id": "ssrstreamwriter",
"hierarchy": [
{
"name": "SSRStreamWriter",
"id": "ssrstreamwriter"
}
],
"kind": "Interface",
"content": "```typescript\nexport interface SSRStreamWriter \n```\n\n\n<table><thead><tr><th>\n\nMethod\n\n\n</th><th>\n\nDescription\n\n\n</th></tr></thead>\n<tbody><tr><td>\n\n[write(chunk)](#ssrstreamwriter-write)\n\n\n</td><td>\n\n\n</td></tr>\n</tbody></table>",
"editUrl": "https://github.com/QwikDev/qwik/tree/main/packages/qwik/src/core/shared/jsx/utils.public.ts",
"mdFile": "core.ssrstreamwriter.md"
},
{
"name": "SVGAttributes",
"id": "svgattributes",
Expand Down Expand Up @@ -2612,6 +2626,23 @@
"content": "Override the `getLocale` with `lang` within the `fn` execution.\n\n\n```typescript\nexport declare function withLocale<T>(locale: string, fn: () => T): T;\n```\n\n\n<table><thead><tr><th>\n\nParameter\n\n\n</th><th>\n\nType\n\n\n</th><th>\n\nDescription\n\n\n</th></tr></thead>\n<tbody><tr><td>\n\nlocale\n\n\n</td><td>\n\nstring\n\n\n</td><td>\n\n\n</td></tr>\n<tr><td>\n\nfn\n\n\n</td><td>\n\n() =&gt; T\n\n\n</td><td>\n\n\n</td></tr>\n</tbody></table>\n\n**Returns:**\n\nT",
"editUrl": "https://github.com/QwikDev/qwik/tree/main/packages/qwik/src/core/use/use-locale.ts",
"mdFile": "core.withlocale.md"
},
{
"name": "write",
"id": "ssrstreamwriter-write",
"hierarchy": [
{
"name": "SSRStreamWriter",
"id": "ssrstreamwriter-write"
},
{
"name": "write",
"id": "ssrstreamwriter-write"
}
],
"kind": "MethodSignature",
"content": "```typescript\nwrite(chunk: JSXOutput): void;\n```\n\n\n<table><thead><tr><th>\n\nParameter\n\n\n</th><th>\n\nType\n\n\n</th><th>\n\nDescription\n\n\n</th></tr></thead>\n<tbody><tr><td>\n\nchunk\n\n\n</td><td>\n\n[JSXOutput](#jsxoutput)\n\n\n</td><td>\n\n\n</td></tr>\n</tbody></table>\n\n**Returns:**\n\nvoid",
"mdFile": "core.ssrstreamwriter.write.md"
}
]
}
66 changes: 64 additions & 2 deletions packages/docs/src/routes/api/qwik/index.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -4500,11 +4500,11 @@ SSRStreamBlock: FunctionComponent<{
```typescript
export type SSRStreamChildren =
| AsyncGenerator<JSXChildren, void, any>
| ((stream: StreamWriter) => Promise<void>)
| ((stream: SSRStreamWriter) => Promise<void>)
| (() => AsyncGenerator<JSXChildren, void, any>);
```

**References:** [JSXChildren](#jsxchildren)
**References:** [JSXChildren](#jsxchildren), [SSRStreamWriter](#ssrstreamwriter)

[Edit this section](https://github.com/QwikDev/qwik/tree/main/packages/qwik/src/core/shared/jsx/utils.public.ts)

Expand All @@ -4520,6 +4520,32 @@ export type SSRStreamProps = {

[Edit this section](https://github.com/QwikDev/qwik/tree/main/packages/qwik/src/core/shared/jsx/utils.public.ts)

## SSRStreamWriter

```typescript
export interface SSRStreamWriter
```

<table><thead><tr><th>

Method

</th><th>

Description

</th></tr></thead>
<tbody><tr><td>

[write(chunk)](#ssrstreamwriter-write)

</td><td>

</td></tr>
</tbody></table>

[Edit this section](https://github.com/QwikDev/qwik/tree/main/packages/qwik/src/core/shared/jsx/utils.public.ts)

## SVGAttributes

The TS types don't include the SVG attributes so we have to define them ourselves
Expand Down Expand Up @@ -9919,3 +9945,39 @@ fn
T

[Edit this section](https://github.com/QwikDev/qwik/tree/main/packages/qwik/src/core/use/use-locale.ts)

## write

```typescript
write(chunk: JSXOutput): void;
```

<table><thead><tr><th>

Parameter

</th><th>

Type

</th><th>

Description

</th></tr></thead>
<tbody><tr><td>

chunk

</td><td>

[JSXOutput](#jsxoutput)

</td><td>

</td></tr>
</tbody></table>

**Returns:**

void
7 changes: 6 additions & 1 deletion packages/qwik/src/core/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,12 @@ export {
SSRComment,
SkipRender,
} from './shared/jsx/utils.public';
export type { SSRStreamProps, SSRHintProps, SSRStreamChildren } from './shared/jsx/utils.public';
export type {
SSRStreamProps,
SSRHintProps,
SSRStreamChildren,
SSRStreamWriter,
} from './shared/jsx/utils.public';
export { Slot } from './shared/jsx/slot.public';
export {
Fragment,
Expand Down
10 changes: 7 additions & 3 deletions packages/qwik/src/core/qwik.core.api.md
Original file line number Diff line number Diff line change
Expand Up @@ -1075,16 +1075,20 @@ export const SSRStreamBlock: FunctionComponent<{
children?: JSXOutput;
}>;

// Warning: (ae-incompatible-release-tags) The symbol "SSRStreamChildren" is marked as @public, but its signature references "StreamWriter" which is marked as @internal
//
// @public (undocumented)
export type SSRStreamChildren = AsyncGenerator<JSXChildren, void, any> | ((stream: StreamWriter) => Promise<void>) | (() => AsyncGenerator<JSXChildren, void, any>);
export type SSRStreamChildren = AsyncGenerator<JSXChildren, void, any> | ((stream: SSRStreamWriter) => Promise<void>) | (() => AsyncGenerator<JSXChildren, void, any>);

// @public (undocumented)
export type SSRStreamProps = {
children: SSRStreamChildren;
};

// @public (undocumented)
export interface SSRStreamWriter {
// (undocumented)
write(chunk: JSXOutput): void;
}

// Warning: (ae-internal-missing-underscore) The name "StreamWriter" should be prefixed with an underscore because the declaration is marked as @internal
//
// @internal (undocumented)
Expand Down
8 changes: 6 additions & 2 deletions packages/qwik/src/core/shared/jsx/utils.public.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import { STREAM_BLOCK_END_COMMENT, STREAM_BLOCK_START_COMMENT } from '../utils/markers';
import type { StreamWriter } from '../../ssr/ssr-types';
import { jsx, RenderOnce } from './jsx-runtime';
import type { FunctionComponent, JSXNode, JSXOutput } from './types/jsx-node';
import type { JSXChildren } from './types/jsx-qwik-attributes';
Expand Down Expand Up @@ -27,10 +26,15 @@ export type SSRStreamProps = {
children: SSRStreamChildren;
};

/** @public */
export interface SSRStreamWriter {
write(chunk: JSXOutput): void;
}

/** @public */
export type SSRStreamChildren =
| AsyncGenerator<JSXChildren, void, any>
| ((stream: StreamWriter) => Promise<void>)
| ((stream: SSRStreamWriter) => Promise<void>)
| (() => AsyncGenerator<JSXChildren, void, any>);

/** @public */
Expand Down
2 changes: 1 addition & 1 deletion packages/qwik/src/core/ssr/ssr-render-jsx.ts
Original file line number Diff line number Diff line change
Expand Up @@ -248,7 +248,7 @@ function processJSXNode(
if (isFunction(generator)) {
value = generator({
async write(chunk) {
await _walkJSX(ssr, chunk as JSXOutput, {
await _walkJSX(ssr, chunk, {
currentStyleScoped: options.styleScoped,
parentComponentFrame: options.parentComponentFrame,
});
Expand Down
28 changes: 27 additions & 1 deletion packages/qwik/src/core/tests/ssr-render.spec.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Slot, useSignal } from '@qwik.dev/core';
import { Slot, useSignal, SSRStreamWriter } from '@qwik.dev/core';
import { ssrRenderToDom, trigger } from '@qwik.dev/core/testing';
import { describe, expect, it } from 'vitest';
import { component$ } from '../shared/component.public';
Expand Down Expand Up @@ -240,5 +240,31 @@ describe('v2 ssr render', () => {
</ul>
);
});

it('should render values from generator with stream from string', async () => {
const { vNode } = await ssrRenderToDom(
<ul>
<SSRStream>
{async function (stream: SSRStreamWriter) {
for (let i = 0; i < 5; i++) {
stream.write(<SSRRaw data={`<li>raw: ${i}</li>`} />);
await delay(10);
}
}}
</SSRStream>
</ul>,
{ debug }
);

expect(vNode).toMatchVDOM(
<ul>
<li>raw: 0</li>
<li>raw: 1</li>
<li>raw: 2</li>
<li>raw: 3</li>
<li>raw: 4</li>
</ul>
);
});
});
});
Loading