@verajs/ssr 0.2.0 → 0.3.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (63) hide show
  1. package/README.md +510 -373
  2. package/dist/vera/diagnostics.d.ts +20 -0
  3. package/dist/vera/diagnostics.js +98 -0
  4. package/dist/vera/escaping.d.ts +142 -0
  5. package/dist/vera/escaping.js +267 -0
  6. package/dist/vera/events.d.ts +41 -0
  7. package/dist/vera/events.js +162 -0
  8. package/dist/vera/frames.d.ts +38 -0
  9. package/dist/vera/frames.js +195 -0
  10. package/dist/vera/index.d.ts +48 -0
  11. package/dist/vera/index.js +480 -0
  12. package/{types → dist/vera}/nodes.d.ts +397 -300
  13. package/dist/vera/nodes.js +2322 -0
  14. package/dist/vera/parse.d.ts +37 -0
  15. package/dist/vera/parse.js +390 -0
  16. package/dist/vera/reflections.d.ts +566 -0
  17. package/dist/vera/reflections.js +820 -0
  18. package/dist/vera/registry.d.ts +14 -0
  19. package/{src → dist}/vera/registry.js +5 -1
  20. package/dist/vera/report.d.ts +27 -0
  21. package/dist/vera/report.js +56 -0
  22. package/dist/vera/scan.d.ts +37 -0
  23. package/dist/vera/scan.js +143 -0
  24. package/dist/vera/select.d.ts +40 -0
  25. package/dist/vera/select.js +261 -0
  26. package/dist/vera/serializer.d.ts +39 -0
  27. package/dist/vera/serializer.js +1372 -0
  28. package/dist/vera/shim.d.ts +42 -0
  29. package/dist/vera/shim.js +853 -0
  30. package/dist/vera/slots.d.ts +5 -0
  31. package/dist/vera/slots.js +104 -0
  32. package/dist/vera/stylesheets.d.ts +62 -0
  33. package/dist/vera/stylesheets.js +180 -0
  34. package/dist/vera/tokenizer.d.ts +32 -0
  35. package/dist/vera/tokenizer.js +528 -0
  36. package/dist/vera/types.d.ts +117 -0
  37. package/dist/vera/views.d.ts +63 -0
  38. package/dist/vera/views.js +245 -0
  39. package/package.json +12 -13
  40. package/src/vera/escaping.js +0 -135
  41. package/src/vera/events.js +0 -164
  42. package/src/vera/frames.js +0 -102
  43. package/src/vera/index.js +0 -1171
  44. package/src/vera/nodes.js +0 -2270
  45. package/src/vera/parse.js +0 -381
  46. package/src/vera/reflections.js +0 -811
  47. package/src/vera/select.js +0 -234
  48. package/src/vera/serializer.js +0 -928
  49. package/src/vera/shim.js +0 -761
  50. package/src/vera/stylesheets.js +0 -155
  51. package/src/vera/views.js +0 -240
  52. package/types/escaping.d.ts +0 -27
  53. package/types/events.d.ts +0 -4
  54. package/types/frames.d.ts +0 -12
  55. package/types/index.d.ts +0 -13
  56. package/types/parse.d.ts +0 -19
  57. package/types/reflections.d.ts +0 -657
  58. package/types/registry.d.ts +0 -8
  59. package/types/select.d.ts +0 -5
  60. package/types/serializer.d.ts +0 -26
  61. package/types/shim.d.ts +0 -23
  62. package/types/stylesheets.d.ts +0 -53
  63. package/types/views.d.ts +0 -26
@@ -1,102 +0,0 @@
1
- /**
2
- * `requestAnimationFrame` on a machine that has no frames.
3
- *
4
- * A server render is one shot: nothing scheduled after the markup is built can reach it. Callbacks
5
- * are queued here and drained by `flushFrames` once a component's `connectedCallback` has returned,
6
- * which is where a browser would run them — deferring is what makes a component's own ordering hold,
7
- * and draining *repeatedly* is what makes the markup match where the client settles.
8
- */
9
-
10
- /** Callbacks awaiting a frame that will not arrive on its own. See `flushFrames`. */
11
- export const frames = [];
12
-
13
- /**
14
- * How many rounds of frames a single server render will run.
15
- *
16
- * Deferring until after `connectedCallback` is what a browser does, and it is what makes a
17
- * component's own ordering hold: work scheduled before `render()` still sees the template. Draining
18
- * *repeatedly* is what makes the markup match where the client settles — an effect that derives
19
- * state schedules a re-render, which is another frame, and stopping after one would ship the
20
- * half-settled DOM this whole area exists to avoid.
21
- *
22
- * The bound is for the component that schedules a frame from inside a frame forever: an animation
23
- * loop, which is browser-only code that happens to be reachable here. It runs a few times and stops
24
- * rather than hanging the request.
25
- */
26
- const FRAME_ROUNDS = 20;
27
-
28
- /**
29
- * Runs everything waiting on a frame, and everything those schedule in turn.
30
- *
31
- * Called once per component, after `connectedCallback` — not inside `requestAnimationFrame` itself.
32
- * Running each callback immediately looked equivalent and was not: two state changes in a row
33
- * re-rendered twice where a browser coalesces them into one, and anything scheduled before
34
- * `render()` ran against a component that had not drawn yet.
35
- */
36
- export const flushFrames = (report) => {
37
- for (let round = 0; round < FRAME_ROUNDS && frames.length; round++) {
38
- const batch = frames.splice(0, frames.length);
39
- for (const frame of batch) {
40
- /**
41
- * One failing callback does not take the others down, because a browser runs each frame
42
- * callback independently and reports a throw rather than abandoning the frame. It is not
43
- * *swallowed* either — `report` collects it, and the render fails at the end naming the
44
- * component, the same way a hook error does.
45
- */
46
- try {
47
- frame?.(performance.now());
48
- } catch (error) {
49
- report?.(error);
50
- }
51
- }
52
- }
53
- /** A loop that never settles leaves work queued; it must not reach the next component. */
54
- frames.length = 0;
55
- };
56
-
57
-
58
- /**
59
- * The same drain, for a render that is allowed to wait.
60
- *
61
- * A frame callback that starts asynchronous work — `navigate()` is the one that matters, and it is
62
- * why a routed component renders an empty outlet today — returns a promise the synchronous drain
63
- * cannot see. Letting the microtask queue run between rounds is what allows that work to finish and
64
- * whatever it schedules to be picked up by the next round.
65
- *
66
- * `await null` rather than a timer: it yields to the microtask queue, which is where a settled
67
- * promise's continuation is waiting, without handing control to the event loop and letting an
68
- * unrelated request interleave more than it already can.
69
- */
70
- export const flushFramesAsync = async (report) => {
71
- /**
72
- * **An empty queue is not the end.** Work started inside a frame may still be in flight — a
73
- * `navigate()` awaits its guards and its route module before it renders anything — so stopping at
74
- * the first empty round ended the drain while the thing it was waiting for had not finished. It
75
- * takes a few consecutive empty turns to conclude that nothing more is coming.
76
- */
77
- let idle = 0;
78
- for (let round = 0; round < FRAME_ROUNDS; round++) {
79
- /** Anything already queued runs first, then whatever it scheduled becomes the next round. */
80
- await null;
81
- if (!frames.length) {
82
- if (++idle >= 3) break;
83
- continue;
84
- }
85
- idle = 0;
86
- const batch = frames.splice(0, frames.length);
87
- for (const frame of batch) {
88
- try {
89
- /**
90
- * **Awaited, unlike the synchronous drain.** A frame callback that returns a promise is
91
- * doing work the markup depends on — the router's initial `navigate()` is exactly that — and
92
- * ignoring it let the render finish while the route was still resolving. The callback ran,
93
- * the route resolved a moment later, and the outlet went out empty.
94
- */
95
- await frame?.(performance.now());
96
- } catch (error) {
97
- report?.(error);
98
- }
99
- }
100
- }
101
- frames.length = 0;
102
- };