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
17 changes: 17 additions & 0 deletions .changeset/fancy-hornets-find.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
---
"@qwikdev/astro": patch
---

feat: Support Qwik Render Options at runtime on a per-component basis.

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.

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.

```astro
<NativeCounter initial={2} renderOpts={{ base: "http://0.0.0.0:4321/build" }} />
```

Make sure to import the `RenderOptions` type from `@builder.io/qwik/server` and pass it to the component for type safety.

Want to make a change for all components? Create a global object config and pass it to each component.
4 changes: 2 additions & 2 deletions apps/demo/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,11 @@
"type": "module",
"version": "0.0.1",
"scripts": {
"dev": "astro dev",
"dev": "astro dev --host 0.0.0.0",
"dev.debug": "node --inspect ./node_modules/astro/astro.js dev",
"start": "astro dev --open",
"build": "astro build",
"preview": "astro preview",
"preview": "astro preview --host 0.0.0.0",
"astro": "astro"
},
"dependencies": {
Expand Down
3 changes: 2 additions & 1 deletion apps/demo/src/components/qwik/counter.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { Slot, component$, useSignal } from "@builder.io/qwik";
import { type RenderOptions } from "@builder.io/qwik/server";

export const Counter = component$<{ initial: number }>((props) => {
export const Counter = component$<{ initial: number; renderOpts?: RenderOptions }>((props) => {
const counter = useSignal(props.initial);

return (
Expand Down
2 changes: 1 addition & 1 deletion apps/demo/src/pages/index.astro
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import { Counter as NativeCounter } from "@components/qwik/counter";
</head>
<body>
<div style={{ height: "1000px" }}>
<NativeCounter initial={2} />
<NativeCounter initial={2} renderOpts={{ base: "http://192.168.68.76:4321/build" }} />
</div>
</body>
</html>
4 changes: 3 additions & 1 deletion libs/qwikdev-astro/server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ export async function renderToStaticMarkup(
props: Record<string, unknown>,
slotted: any
) {

try {
if (!isQwikComponent(component)) {
return;
Expand All @@ -72,6 +73,7 @@ export async function renderToStaticMarkup(
const isInitialContainer = !containerMap.has(this.result);

const renderToStreamOpts: RenderToStreamOptions = {
...(props.renderOpts ?? {}),
containerAttributes: {
style: "display: contents",
...(isDev && { "q-astro-marker": "" })
Expand All @@ -90,7 +92,7 @@ export async function renderToStaticMarkup(
write: (chunk) => {
html += chunk;
}
}
},
};

// https://qwik.dev/docs/components/overview/#inline-components
Expand Down
Loading