Skip to content

Commit 7d7b656

Browse files
feat: support render opts on a component basis (#268)
* feat: support render opts on a component basis * changeset
1 parent 393e4ff commit 7d7b656

File tree

5 files changed

+25
-5
lines changed

5 files changed

+25
-5
lines changed

.changeset/fancy-hornets-find.md

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
---
2+
"@qwikdev/astro": patch
3+
---
4+
5+
feat: Support Qwik Render Options at runtime on a per-component basis.
6+
7+
This is useful for scenarios where you want to render a Qwik component in an Astro page, but you want to use a different base URL for the Qwik component, or another configuration.
8+
9+
For example, if you want to render a Qwik component in an Astro page, but you want to use a different base URL for the Qwik component, you can pass the `renderOpts` prop to the Qwik component.
10+
11+
```astro
12+
<NativeCounter initial={2} renderOpts={{ base: "http://0.0.0.0:4321/build" }} />
13+
```
14+
15+
Make sure to import the `RenderOptions` type from `@builder.io/qwik/server` and pass it to the component for type safety.
16+
17+
Want to make a change for all components? Create a global object config and pass it to each component.

apps/demo/package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,11 @@
44
"type": "module",
55
"version": "0.0.1",
66
"scripts": {
7-
"dev": "astro dev",
7+
"dev": "astro dev --host 0.0.0.0",
88
"dev.debug": "node --inspect ./node_modules/astro/astro.js dev",
99
"start": "astro dev --open",
1010
"build": "astro build",
11-
"preview": "astro preview",
11+
"preview": "astro preview --host 0.0.0.0",
1212
"astro": "astro"
1313
},
1414
"dependencies": {

apps/demo/src/components/qwik/counter.tsx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import { Slot, component$, useSignal } from "@builder.io/qwik";
2+
import { type RenderOptions } from "@builder.io/qwik/server";
23

3-
export const Counter = component$<{ initial: number }>((props) => {
4+
export const Counter = component$<{ initial: number; renderOpts?: RenderOptions }>((props) => {
45
const counter = useSignal(props.initial);
56

67
return (

apps/demo/src/pages/index.astro

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ import { Counter as NativeCounter } from "@components/qwik/counter";
1212
</head>
1313
<body>
1414
<div style={{ height: "1000px" }}>
15-
<NativeCounter initial={2} />
15+
<NativeCounter initial={2} renderOpts={{ base: "http://192.168.68.76:4321/build" }} />
1616
</div>
1717
</body>
1818
</html>

libs/qwikdev-astro/server.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,7 @@ export async function renderToStaticMarkup(
6161
props: Record<string, unknown>,
6262
slotted: any
6363
) {
64+
6465
try {
6566
if (!isQwikComponent(component)) {
6667
return;
@@ -72,6 +73,7 @@ export async function renderToStaticMarkup(
7273
const isInitialContainer = !containerMap.has(this.result);
7374

7475
const renderToStreamOpts: RenderToStreamOptions = {
76+
...(props.renderOpts ?? {}),
7577
containerAttributes: {
7678
style: "display: contents",
7779
...(isDev && { "q-astro-marker": "" })
@@ -90,7 +92,7 @@ export async function renderToStaticMarkup(
9092
write: (chunk) => {
9193
html += chunk;
9294
}
93-
}
95+
},
9496
};
9597

9698
// https://qwik.dev/docs/components/overview/#inline-components

0 commit comments

Comments
 (0)