Skip to content

Commit 9265532

Browse files
update @qwikdev/astro docs
1 parent fcfe1c6 commit 9265532

File tree

1 file changed

+46
-37
lines changed

1 file changed

+46
-37
lines changed

libs/qwikdev-astro/README.md

Lines changed: 46 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ at the top of each Qwik component file.
7676
7777
This is when you may not have that many Qwik components compared to other JSX frameworks on the page.
7878
79-
If you face any issues, please [post them on Github](https://github.com/QwikDev/astro/issues) and attempt the manual installation below.
79+
If you face any issues, [post them on Github](https://github.com/QwikDev/astro/issues) and attempt the manual installation below.
8080
8181
### Manual Installation
8282
@@ -108,21 +108,19 @@ Now, add the integration to your `astro.config.*` file using the `integrations`
108108
109109
## Key differences
110110
111-
Hooray! We now have our integration installed. Before deep diving in, there are quite a few differences than other UI frameworks.
111+
Before deep diving in, there are quite a few differences than other UI frameworks.
112112
113113
## Qwik does not hydrate, it is **fundamentally different**
114114
115115
Astro is popular for its partial hydration approach, whereas Qwik [does not require hydration](https://www.builder.io/blog/hydration-tree-resumability-map#resumability-is-fundamentally-a-different-algorithm).
116116
117-
What does this mean?
118-
119117
### Qwik components **do not need hydration directives**
120118
121119
In other UI frameworks, a hydration directive would be needed for interactivity, such as `client:only` or `client:load`. These are not needed with Qwik, because there is no hydration!
122120
123121
When using Qwik inside a meta framework like Astro or Qwik City, components are loaded on the server, prefetched in a separate thread, and "resumed" on the client.
124122
125-
For example here's how we create a counter component in Qwik (e.g. at `src/components/counter.tsx`).
123+
For example here's how to create a counter component in Qwik (e.g. at `src/components/counter.tsx`).
126124

127125
```tsx
128126
import { component$, useSignal } from "@builder.io/qwik";
@@ -134,7 +132,7 @@ export const Counter = component$(() => {
134132
});
135133
```
136134
137-
It can be consumed in our `index.astro` page like so:
135+
It can be consumed in an `index.astro` page like so:
138136
139137
```astro
140138
---
@@ -157,23 +155,21 @@ It can be consumed in our `index.astro` page like so:
157155
</html>
158156
```
159157
160-
Let's take a look at this in the wild.
161-
162158
![A gif showing a button clicked and the onClick$ resumed](https://i.imgur.com/unp1MRN.gif)
163159
164-
Here we are refreshing the page, and you'll notice nothing was executed until the button was clicked. Without resumability, our `<Counter />` would have been executed on page load.
160+
The above example refreshes the page, and notice nothing was executed until the button was clicked. Without resumability, the `<Counter />` would have been executed on page load.
165161
166162
The 402 byte q-chunk is our Counter's `onClick$` handler.
167163
168164
#### What's in that 17.61kb chunk?
169165
170-
The framework! We do not execute it until it is needed. In this case it is gzipped using SSG.
166+
The framework! It is not executed until needed. In this case it is gzipped using SSG.
171167
172168
## Starts fast, stays fast
173169
174170
One of Astro's key features is **Zero JS, by default**. Unfortunately, after adding a JavaScript framework, and any subsequent components this is usually not the case.
175171
176-
If we want to introduce interactivity with a framework such as React, Vue, Svelte, etc., the framework runtime is then introduced. The number of components added to the page also increases linearly O(n) with the amount of JavaScript.
172+
When introducing interactivity with a framework such as React, Vue, Svelte, etc., the framework runtime is then introduced. The number of components added to the page also increases linearly O(n) with the amount of JavaScript.
177173
178174
### Astro + Qwik
179175
@@ -187,11 +183,11 @@ Instead, upon page load, a tiny 1kb minified piece of JavaScript, known as the [
187183
188184
Hydration forces your hand [to eagerly execute code](https://www.builder.io/blog/hydration-sabotages-lazy-loading). It's not a problem with components that are outside of the tree, such as modals, but it must exhaustively check each component in the render tree just in case.
189185
190-
Qwik works exceptionally well in Astro due to Resumability and its ability to lazy load code in a fine-grained manner. Especially for marketing sites, blogs, and content oriented sites with many components.
186+
Qwik works well in Astro due to Resumability and its ability to lazy load code in a fine-grained manner. The moment JavaScript interactivity is involved, use Qwik. Some examples include marketing sites, blogs, content oriented sites, e-commerce applications, and even full-blown web-apps at scale.
191187
192188
### Instant interactivity
193189
194-
As of `@qwikdev/astro` v0.4, we have added support for [Speculative Module Fetching](https://qwik.builder.io/docs/advanced/speculative-module-fetching/) in Astro.
190+
As of `@qwikdev/astro` v0.4, there is support for [Speculative Module Fetching](https://qwik.builder.io/docs/advanced/speculative-module-fetching/) in Astro.
195191
196192
This enables instant interactivity for your Qwik components. Speculative module fetching will prefetch the application bundles in the background of a service worker, so that when needed, the code is already present in the browser cache.
197193
@@ -203,9 +199,9 @@ While Astro generally adopts an islands architecture with other frameworks, Qwik
203199
204200
![An example of a Qwik container](https://i.imgur.com/hJJtRHj.jpeg)
205201
206-
In the DOM, you'll notice there aren't any `<astro-island>` custom elements, this is because to Astro, Qwik looks like static data.
202+
In the DOM, notice there aren't any `<astro-island>` custom elements, this is because to Astro, Qwik looks like static data.
207203
208-
> This is because in Qwik, the handlers themselves are the roots / entrypoints of the application.
204+
> In Qwik, the handlers themselves are the roots / entrypoints of the application.
209205
210206
### Communicating across containers
211207
@@ -227,7 +223,7 @@ For example, in Solid's tutorial the following is mentioned:
227223
228224
In Qwik, it was a design decision to not include global signal state.
229225
230-
Instead, we recommend the use of **custom events**, which offer several advantages:
226+
Instead, use **custom events**, which offer several advantages:
231227
232228
- Performance (avoid unnecessary state synchronization)
233229
- Does not wake up the framework on page load
@@ -236,7 +232,7 @@ Instead, we recommend the use of **custom events**, which offer several advantag
236232
- Event Driven
237233
- Decoupled
238234
239-
[This example](https://github.com/thejackshelton/astro-qwik-global-state-example/blob/main/src/components/counter.tsx) shows how custom events can be used throughout your application. Pay attention to `counter.tsx`, `random-island.tsx`, and our `index.astro` page.
235+
[This example](https://github.com/thejackshelton/astro-qwik-global-state-example/blob/main/src/components/counter.tsx) shows how custom events can be used throughout your application. Pay attention to `counter.tsx`, `random-island.tsx`, and the `index.astro` page.
240236
241237
## Using multiple JSX frameworks
242238
@@ -258,15 +254,15 @@ export default defineConfig({
258254
});
259255
```
260256
261-
Above we're using the Qwik, React, and Solid integrations in the same Astro project.
257+
Above the code snippet uses the Qwik, React, and Solid integrations in the same Astro project.
262258
263-
If we look at the first integration, it's going to look for any file in the `qwik` folder and use Qwik for any file in this folder.
259+
The first integration in the snippet above, looks for any file in the `qwik` folder and uses Qwik for any file in this folder.
264260
265261
For simplicity, consider grouping common framework components in the same folder (like `/components/react/` and `/components/qwik/`). However, this is optional.
266262
267263
### Qwik React
268264
269-
If you're using React, we suggest using the `@builder.io/qwik-react` integration. It's a drop-in replacement for `@astrojs/react`, and allows a seamless transition to Qwik.
265+
If you're using React, use the [Qwik-React integration](https://qwik.dev/docs/integrations/react/). It's a drop-in replacement for `@astrojs/react`, and allows a seamless transition to Qwik.
270266
271267
```tsx
272268
import { defineConfig } from "astro/config";
@@ -283,9 +279,9 @@ export default defineConfig({
283279
});
284280
```
285281
286-
With Qwik-React, we can "qwikify" our React components, and use them in our Qwik application, even nesting Qwik and React components outside of an Astro file!
282+
The Qwik-React integration allows you to use React components directly in Qwik.
287283
288-
> You do not need to specify an include property with qwikReact.
284+
> You do not need to specify an include property with Qwik-React.
289285
290286
[Here's an example](https://github.com/thejackshelton/qwik-react-astro-template) of a React component with the `qwik-react` integration.
291287
@@ -304,17 +300,17 @@ const ReactCounter = () => {
304300
export const QReactCounter = qwikify$(ReactCounter);
305301
```
306302
307-
After creating our counter, it can be consumed in our [index.astro](https://github.com/thejackshelton/qwik-react-astro-template/blob/main/src/pages/index.astro) file.
303+
After creating our counter, it can be consumed in the [index.astro](https://github.com/thejackshelton/qwik-react-astro-template/blob/main/src/pages/index.astro) file.
308304
309305
```tsx
310306
<QReactCounter qwik:visible />
311307
```
312308
313-
Notice that in `.astro` files we use a `qwik:` hydration directive prefix, this is to prevent a conflict with Astro's hydration directives that are provided out of the box.
309+
Notice that in `.astro` files there is a `qwik:` hydration directive prefix, this is to prevent a conflict with Astro's hydration directives that are provided out of the box.
314310
315-
You can also use the `client:*` prefix, but only in tsx files. You can find a list of directives in [Adding Interactivity](https://qwik.builder.io/docs/integrations/react/#adding-interactivity) section of the Qwik docs.
311+
You can also use the `client:*` prefix, but only in tsx files. You can find a list of directives in the Qwik-React [Adding Interactivity](https://qwik.builder.io/docs/integrations/react/#adding-interactivity) section of the Qwik docs.
316312
317-
> Qwik React components still have hydration, thus it is recommended to use Qwik-React as a migration strategy to resumable components.
313+
> Qwik React components still have hydration. It is recommended to use Qwik-React as a migration strategy to resumable components.
318314
319315
### jsxImportSource
320316
@@ -370,38 +366,51 @@ export const MySlotComp = component$<{ initial: number }>((props) => {
370366
</MySlotComp>
371367
```
372368
373-
Default slots work as expected in their Qwik City counterpart.
369+
## Community Guides
370+
371+
- [Embed Stackblitz in a performant way](https://thenewstack.io/how-to-build-embed-components-with-astro-qwik-and-stackblitz/)
374372
375-
## Starter Kits
373+
- [Build a Site Search with Astro, Qwik and Fuse.js](https://thenewstack.io/how-to-build-site-search-with-astro-qwik-and-fuse-js/)
376374
377-
- [Siguici's](https://github.com/siguici) [@qwikdev/astro + Deno](https://github.com/siguici/qwik-astro-deno) starter kit
375+
- [Qwik as a React alternative](https://thenewstack.io/take-a-qwik-break-from-react-with-astro/) in Astro.
378376
379-
## Community Guides
377+
- [Deploy Qwik Astro with the Vercel SSR Adapter](https://dev.to/reeshee/qwik-look-at-resumability-with-astro-on-vercel-44fj).
380378
381-
- [Paul Scanlon](https://www.paulie.dev/) shows a hands-on look at [using Qwik in Astro over React and Vanilla JS](https://thenewstack.io/how-quiks-astro-integration-beats-both-react-and-vanilla-js/).
379+
- [Netlify's Guide to starting a Qwik Astro project](https://developers.netlify.com/guides/adding-resumability-to-astro-with-qwik/)
382380
383-
- [Rishi Raj Jain](https://twitter.com/rishi_raj_jain_) has written an awesome guide on setting up Qwik with Astro's [Vercel SSR Adapter](https://dev.to/reeshee/qwik-look-at-resumability-with-astro-on-vercel-44fj).
381+
- [Using Qwik in Astro over React and Vanilla JS](https://thenewstack.io/how-quiks-astro-integration-beats-both-react-and-vanilla-js/).
384382
385-
- [Paul Scanlon](https://www.paulie.dev/) explores using [Qwik as a React alternative](https://thenewstack.io/take-a-qwik-break-from-react-with-astro/) in Astro.
383+
- [Initial @qwikdev/astro Alpha Post](https://www.builder.io/blog/astro-qwik)
386384
387385
## Videos
388386
389-
- Watch Jason & Steve [discuss the Qwik Astro integration](https://www.youtube.com/watch?v=W-j2HH1GdjU&t=0s) on the [LWJ show](https://www.youtube.com/@learnwithjason).
387+
- Steve's [Qwik Astro announcement video](https://www.youtube.com/watch?v=LIKxkSzHqeo)
390388
391389
- [Awesome's Qwik + Astro video](https://www.youtube.com/watch?v=wKvkYUNBa5k) goes into how Astro just got even faster.
392390
391+
- Watch Jason & Steve [discuss the Qwik Astro integration](https://www.youtube.com/watch?v=W-j2HH1GdjU&t=0s) on the [LWJ show](https://www.youtube.com/@learnwithjason).
392+
393+
- [JLarky's insights on Qwik and potentially RSC in Astro](https://www.youtube.com/shorts/aaJuBrgQQDk)
394+
395+
## Talks
396+
397+
- [Astro and Qwik - a match made in performance heaven! - DevWorld 2024](https://www.youtube.com/watch?v=OSIjoqVK51o)
398+
- [Astro: A New Era of Effective Lazy Loading (fr)](https://www.youtube.com/watch?v=OgRfNfCMvvQ)
399+
393400
## Contributing
394401
395-
We'd love for you to contribute! Start by reading our [Contributing Guide](https://github.com/QwikDev/astro/blob/main/contributing.md). It's got all the info you need to get involved, including an in-depth section on how the integration works under the hood.
402+
Start by reading our [Contributing Guide](https://github.com/QwikDev/astro/blob/main/contributing.md). It includes how to get involved, and an in-depth section on how the integration works under the hood.
403+
404+
## Help
396405
397-
There's also a `qwik-astro` channel in the builder.io discord to discuss API changes, possible ideas to the integration, and other cool stuff. 😊
406+
If you're stuck, reach out in the Astro discord or the [Qwik discord](https://discord.gg/p7E6mgXGgF), which has a dedicated [qwik-astro](https://discord.com/channels/842438759945601056/1150941080355881080) channel. Problems directly related to the integration can be created [as an issue](https://github.com/QwikDev/astro/issues).
398407
399408
## Credits
400409
401410
### Maintainers
402411
403412
- [Jack Shelton](https://twitter.com/TheJackShelton)
404-
- [Sigui](https://twitter.com/siguici)
413+
- [Sigui Kessé Emmanuel](https://twitter.com/siguici)
405414
406415
### Astro Core Team
407416

0 commit comments

Comments
 (0)