You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: packages/docs/src/routes/api/qwik-server/api.json
+14Lines changed: 14 additions & 0 deletions
Original file line number
Diff line number
Diff line change
@@ -2,6 +2,20 @@
2
2
"id": "qwik-server",
3
3
"package": "@qwik.dev/qwik/server",
4
4
"members": [
5
+
{
6
+
"name": "getQwikBackpatchExecutorScript",
7
+
"id": "getqwikbackpatchexecutorscript",
8
+
"hierarchy": [
9
+
{
10
+
"name": "getQwikBackpatchExecutorScript",
11
+
"id": "getqwikbackpatchexecutorscript"
12
+
}
13
+
],
14
+
"kind": "Function",
15
+
"content": "Provides the `backpatch-executor.js` executor script as a string.\n\n\n```typescript\nexport declare function getQwikBackpatchExecutorScript(opts?: {\n debug?: boolean;\n}): string;\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\nopts\n\n\n</td><td>\n\n{ debug?: boolean; }\n\n\n</td><td>\n\n_(Optional)_\n\n\n</td></tr>\n</tbody></table>\n\n**Returns:**\n\nstring",
Similar to the [Qwikloader](../qwikloader/index.mdx) that executes a small script, backpatching updates nodes already streamed on the server without waking up the Qwik runtime.
12
+
13
+
> Most useful when building component libraries or apps with interdependent elements that render in varying orders.
14
+
15
+
### What it is
16
+
17
+
Backpatching solves a fundamental difference between client and server rendering:
18
+
19
+
**Client rendering**: Components can render in any order, then establish relationships between each other afterward.
20
+
21
+
**SSR streaming**: Once HTML is sent to the browser, it's immutable—you can only stream more content forward.
22
+
23
+
This creates problems for component libraries where elements need to reference each other (like form inputs linking to their labels via `aria-labelledby`). If the input streams before its label, it can't know the label's ID to set the relationship.
24
+
25
+
Backpatching automatically fixes these relationships by updating attributes after the entire page has streamed, giving you the same flexibility as client-side rendering.
26
+
27
+
> Note: This is not Out-of-Order Streaming. It only corrects already-sent attributes without delaying the stream.
{/* If the description component is not passed, it is a broken aria reference without backpatching, as the input would try to describe an element that does not exist */}
- Without backpatching, `<Input />` would never know about `<Description />`, leading to incorrect accessibility relationships.
75
+
76
+
- With backpatching, the aria-describedby attribute on `<Input>` will be automatically corrected even if `<Description>` runs after the input was streamed.
77
+
78
+
### Limitations
79
+
80
+
-**Attributes only**: Backpatching is currently limited to updating attributes. It does not change element children/text/structure.
81
+
82
+
### How it works (high level)
83
+
84
+
Here's how backpatching works under the hood:
85
+
86
+
1.**During Server-side streaming**: When a component tries to update an attribute on an element that's already been sent to the browser, Qwik detects this and remembers the intended change.
87
+
88
+
2.**Element Tracking**: Qwik assigns each element a unique index based on its position in the DOM tree, so it can reliably find the same element in the browser.
89
+
90
+
3.**Script Generation**: Instead of blocking the stream, Qwik generates a tiny JavaScript snippet that will run later to apply the fix.
91
+
92
+
4.**Browser Execution**: On page load, this script uses efficient DOM traversal to find and update the target elements with their correct attribute values.
93
+
94
+
5.**Zero Runtime Impact**: This all happens without waking up the Qwik framework, keeping your app fast and lightweight.
"exports_annotation": "We use the build for the optimizer because esbuild doesn't like the html?raw imports in the server plugin and it's only used in the vite configs",
0 commit comments