Skip to content

Commit 6902c40

Browse files
authored
Merge pull request #7974 from QwikDev/fix-css-properties
fix: repl and tutorial improvements
2 parents 6497a46 + 1ff50b6 commit 6902c40

File tree

12 files changed

+60
-65
lines changed

12 files changed

+60
-65
lines changed

packages/docs/src/repl/bundler/repl-ssr-worker.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
// SSR Worker - handles server-side rendering execution
22
// MUST be served from /repl/ so that its imports are intercepted by the REPL service worker
33
import type { QwikManifest } from '@builder.io/qwik/optimizer';
4+
import type { RenderToString } from '@builder.io/qwik/server';
45
import type { ReplEvent } from '../types';
56

67
// Worker message types
@@ -80,7 +81,7 @@ async function executeSSR(message: InitSSRMessage): Promise<{ html: string; even
8081
const module = await importFrom(`/repl/ssr/${replId}/${entry}`);
8182
const server = module.default;
8283

83-
const render = typeof server === 'function' ? server : server?.render;
84+
const render: RenderToString = typeof server === 'function' ? server : server?.render;
8485
if (typeof render !== 'function') {
8586
throw new Error(`Server module ${entry} does not export default render function`);
8687
}
@@ -109,6 +110,7 @@ async function executeSSR(message: InitSSRMessage): Promise<{ html: string; even
109110
base: baseUrl,
110111
manifest,
111112
prefetchStrategy: null,
113+
preloader: false,
112114
});
113115

114116
events.push({

packages/docs/src/repl/bundler/rollup-plugins.ts

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -35,13 +35,14 @@ export const replResolver = (
3535
return srcInputs.find((i) => i.path === id)?.path;
3636
};
3737

38-
const getQwik = (id: string, external?: true) => {
38+
const resolveQwik = (id: string, external?: true) => {
3939
const path = deps[QWIK_PKG_NAME_V1][id];
4040
if (!path) {
4141
throw new Error(`Unknown Qwik path: ${id}`);
4242
}
4343
return {
44-
id: `\0@qwik${id}`,
44+
// Make sure this matches the regexes in manifest.ts
45+
id: `/node_modules/@qwik.dev/core${id}`,
4546
sideEffects: false,
4647
// It would be nice to load qwik as external, but
4748
// we import core and core/build so we need processing
@@ -58,30 +59,30 @@ export const replResolver = (
5859
if (id.startsWith('http')) {
5960
return { id, external: true };
6061
}
61-
if (id.startsWith('\0@qwik/')) {
62+
if (id.startsWith('/node_modules/@qwik.dev/core/')) {
6263
return id;
6364
}
6465
const match = id.match(/(@builder\.io\/qwik|@qwik\.dev\/core)(.*)/);
6566
if (match) {
6667
const pkgName = match[2];
6768

6869
if (pkgName === '/build') {
69-
return `\0@qwik/build`;
70+
return `/node_modules/@qwik.dev/core/build`;
7071
}
7172
if (!pkgName || pkgName === '/jsx-runtime' || pkgName === '/jsx-dev-runtime') {
72-
return getQwik('/dist/core.mjs');
73+
return resolveQwik('/dist/core.mjs');
7374
}
7475
if (pkgName === '/server') {
75-
return getQwik('/dist/server.mjs');
76+
return resolveQwik('/dist/server.mjs');
7677
}
7778
if (pkgName.includes('/preloader')) {
78-
return getQwik('/dist/preloader.mjs');
79+
return resolveQwik('/dist/preloader.mjs');
7980
}
8081
if (pkgName.includes('/qwikloader')) {
81-
return getQwik('/dist/qwikloader.js');
82+
return resolveQwik('/dist/qwikloader.js');
8283
}
8384
if (pkgName.includes('/handlers')) {
84-
return getQwik('/handlers.mjs');
85+
return resolveQwik('/handlers.mjs');
8586
}
8687
}
8788
// Simple relative file resolution
@@ -107,8 +108,8 @@ export const replResolver = (
107108
if (input && typeof input.code === 'string') {
108109
return input.code;
109110
}
110-
if (id.startsWith('\0@qwik/')) {
111-
const path = id.slice('\0@qwik'.length);
111+
if (id.startsWith('/node_modules/@qwik.dev/core/')) {
112+
const path = id.slice('/node_modules/@qwik.dev/core'.length);
112113
if (path === '/build') {
113114
// Virtual module for Qwik build
114115
const isDev = options.buildMode === 'development';

packages/docs/src/routes/examples/apps/reactivity/auto-complete/app.tsx

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ export default component$(() => {
77
<br />
88
<br />
99
Go ahead, search for Star Wars characters such as "Luke Skywalker", it uses the{' '}
10-
<a href="https://swapi-node.vercel.app/">Star Wars API</a>:
10+
<a href="https://swapi.py4e.com/">Star Wars API</a>:
1111
<br />
1212
<br />
1313
<AutoComplete></AutoComplete>
@@ -68,16 +68,16 @@ export const SuggestionsListComponent = (props: { state: IState }) => {
6868
};
6969

7070
const getPeople = (searchInput: string, controller?: AbortController): Promise<string[]> =>
71-
fetch(`https://swapi-node.vercel.app/api/people/?search=${searchInput}`, {
71+
fetch(`https://swapi.py4e.com/api/people/?search=${searchInput}`, {
7272
signal: controller?.signal,
7373
})
7474
.then((response) => {
7575
return response.json();
7676
})
7777
.then((parsedResponse) => {
78-
debugger;
79-
return parsedResponse.results.map((people: any) => people.fields.name);
80-
});
78+
return parsedResponse.results.map((people: { name: string }) => people.name);
79+
})
80+
.catch((e) => console.error('fetch failed', e));
8181

8282
function debounce<F extends (...args: any) => any>(fn: F, delay = 500) {
8383
let timeoutId: ReturnType<typeof setTimeout>;

packages/docs/src/routes/tutorial/events/synchronous-sync/index.mdx

Lines changed: 31 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -15,17 +15,24 @@ created_at: '2022-08-02T12:07:45Z'
1515

1616
While not a common use case, you may occasionally need to process events synchronously.
1717

18-
Since Qwik processes asynchronously by default, your code must be explicitly configured for synchronous calls.
18+
The two most common use cases are to call `event.preventDefault()` or `event.stopPropagation()` on a DOM event. Those are handled by adding the `preventdefault:eventname` or `stoppropagation:eventname` in addition to your event handler.
1919

20-
There are two ways of processing events synchronously:
21-
1. preferred way: use `sync$()` to load code synchronously. Fast, resumable but with **significant restrictions** on event handler size.
22-
2. eager registration: use `useVisibleTask$()` to load code synchronously. No restrictions, but requires eager code execution, which goes against resumability.
20+
```tsx
21+
<a href="/" preventdefault:click onClick$={() => {
22+
console.log('clicked');
23+
}}>
24+
link
25+
</a>
26+
```
2327

24-
This example shows how to use synchronous code blocks using `sync$()`.
28+
When you have other use cases that require synchronous event processing, you can use either `sync$()` or `useVisibleTask$()`.
29+
1. preferred way: use `sync$()` to embed the code in the HTML. Fast, resumable, but with some restrictions (see below).
30+
2. eager registration: use `useVisibleTask$()` to register a handler. No restrictions, but it will not handle events until the visible task has executed, and it will cause of course run extra javaScript while the page is loading.
2531

2632
```tsx
2733
<a href="/"
2834
onClick$={sync$((event, target) => {
35+
// Only prevent default if the ctrl key is pressed.
2936
if (event.ctrlKey) {
3037
event.preventDefault();
3138
}
@@ -34,7 +41,7 @@ This example shows how to use synchronous code blocks using `sync$()`.
3441
</a>
3542
```
3643

37-
## `sync$()` Restrictions (BETA)
44+
## `sync$()` Restrictions
3845

3946
The `sync$()` function is a resumable way to process events synchronously. However, it has some significant restrictions. The `sync$()` **can't close over anything**. The implications are that you can't:
4047
- access any state: The recommended way to get the state into function is to place on element attributes.
@@ -63,6 +70,23 @@ For this reason, we recommended breaking up the event handlers into two parts:
6370
</a>
6471
```
6572

73+
You can also dispatch a custom event from the `sync$()` handler and handle it asynchronously:
6674

75+
```tsx
76+
<a href="/"
77+
onClick$={sync$((event, target) => {
78+
if (event.ctrlKey) {
79+
event.preventDefault();
80+
}
81+
// Dispatch a custom event to be handled asynchronously.
82+
target.dispatchEvent(new CustomEvent('myclick', { bubbles: true }));
83+
})}
84+
onMyclick$={() => {
85+
// This part can be asynchronous and can close over anything.
86+
console.log('clicked');
87+
}}>
88+
link
89+
</a>
90+
```
6791

68-
**Your task:** Convert the `onClick$` from asynchronous event to synchronous event by using [`useVisibleTask$`](/docs/(qwik)/core/tasks/index.mdx#usevisibletask) lifecycle and [normal event registration](https://developer.mozilla.org/en-US/docs/Web/API/EventTarget/addEventListener).
92+
**Your task:** Convert the `onClick$` from asynchronous event to synchronous event by using [`sync$`](/docs/(qwik)/core/tasks/index.mdx#usevisibletask).

packages/docs/src/routes/tutorial/hooks/use-un-mount/index.mdx

Lines changed: 0 additions & 17 deletions
This file was deleted.

packages/docs/src/routes/tutorial/hooks/use-un-mount/problem/app.tsx

Lines changed: 0 additions & 5 deletions
This file was deleted.

packages/docs/src/routes/tutorial/hooks/use-un-mount/solution/app.tsx

Lines changed: 0 additions & 5 deletions
This file was deleted.

packages/docs/src/routes/tutorial/projection/fallback/index.mdx

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@ created_at: '2022-08-02T12:07:45Z'
1111

1212
Fallback content allows the child component to display fallback content in case the parent component did not provide content. The fallback content can be done with CSS, it is necessary to add a CSS selector (and the appropriate CSS) on the named Slot in case it is empty.
1313

14+
Note that in the upcoming Qwik 2.0, a Slot can embed fallback content directly, without needing CSS.
15+
1416
### Example
1517

1618
In this example, we show three cards, but some of them are not filled with content. Use the right CSS selector to specify the fallback content.
File renamed without changes.
File renamed without changes.

0 commit comments

Comments
 (0)