@valbuild/next 0.150.23 → 0.152.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 (76) hide show
  1. package/CHANGELOG.md +175 -0
  2. package/README.md +82 -1
  3. package/client/dist/valbuild-next-client.cjs.dev.js +123 -256
  4. package/client/dist/valbuild-next-client.cjs.prod.js +123 -256
  5. package/client/dist/valbuild-next-client.esm.js +122 -255
  6. package/dist/{ValApp-a88a9ded.esm.js → ValApp-69cd599c.esm.js} +3 -3
  7. package/dist/{ValApp-c718d1a6.cjs.dev.js → ValApp-826dca6c.cjs.dev.js} +3 -3
  8. package/dist/ValApp-866089f6.cjs.js +7 -0
  9. package/dist/{ValApp-6c3da222.cjs.prod.js → ValApp-866089f6.cjs.prod.js} +3 -3
  10. package/dist/{ValCanvasBridge-9d221d32.cjs.dev.js → ValCanvasBridge-4b81f653.cjs.dev.js} +46 -13
  11. package/dist/ValCanvasBridge-6f568f1d.cjs.js +7 -0
  12. package/dist/{ValCanvasBridge-134c3ae1.cjs.prod.js → ValCanvasBridge-6f568f1d.cjs.prod.js} +46 -13
  13. package/dist/{ValCanvasBridge-4a5ef73c.esm.js → ValCanvasBridge-badc186b.esm.js} +46 -13
  14. package/dist/ValNextProvider-41d622a7.cjs.js +7 -0
  15. package/dist/{ValNextProvider-35d0b521.cjs.prod.js → ValNextProvider-41d622a7.cjs.prod.js} +124 -234
  16. package/dist/{ValNextProvider-a85a1d33.cjs.dev.js → ValNextProvider-4b9bcfc0.cjs.dev.js} +124 -234
  17. package/dist/{ValNextProvider-df6f351e.esm.js → ValNextProvider-745ed99e.esm.js} +124 -234
  18. package/dist/ValOverlayContext-0c29b6a7.cjs.dev.js +51 -0
  19. package/dist/ValOverlayContext-0f51d111.cjs.js +7 -0
  20. package/dist/ValOverlayContext-0f51d111.cjs.prod.js +51 -0
  21. package/dist/ValOverlayContext-178db68e.esm.js +37 -0
  22. package/dist/ValVideo-02f43a7c.cjs.js +7 -0
  23. package/dist/{ValVideo-dcd2b9f8.cjs.prod.js → ValVideo-02f43a7c.cjs.prod.js} +1 -2
  24. package/dist/{ValVideo-6e410ad8.cjs.dev.js → ValVideo-15e5c4fa.cjs.dev.js} +1 -2
  25. package/dist/{ValVideo-d377f06e.esm.js → ValVideo-8acf31b6.esm.js} +1 -2
  26. package/dist/{createForOfIteratorHelper-d4afcad8.cjs.prod.js → createForOfIteratorHelper-8459fbc7.cjs.prod.js} +1 -1
  27. package/dist/{createForOfIteratorHelper-5758a730.esm.js → createForOfIteratorHelper-9209e9dd.esm.js} +1 -1
  28. package/dist/{createForOfIteratorHelper-0445603c.cjs.dev.js → createForOfIteratorHelper-9c6aa3c7.cjs.dev.js} +1 -1
  29. package/dist/declarations/src/ValProvider.d.ts +1 -0
  30. package/dist/declarations/src/client/initValClient.d.ts +25 -3
  31. package/dist/declarations/src/external_exempt_from_val_quickjs.d.ts +1 -0
  32. package/dist/declarations/src/rsc/index.d.ts +1 -0
  33. package/dist/declarations/src/rsc/initValRsc.d.ts +56 -118
  34. package/dist/{fallbackColors-149dfbc9.esm.js → fallbackColors-0d915c59.esm.js} +1 -1
  35. package/dist/{fallbackColors-080c1bbc.cjs.dev.js → fallbackColors-38f01ad2.cjs.dev.js} +1 -1
  36. package/dist/{fallbackColors-e1d73b36.cjs.prod.js → fallbackColors-d9a7b81e.cjs.prod.js} +1 -1
  37. package/dist/{objectSpread2-13f847a9.cjs.prod.js → objectSpread2-469273e9.cjs.prod.js} +25 -2
  38. package/dist/{objectSpread2-58024783.cjs.dev.js → objectSpread2-58726b14.cjs.dev.js} +25 -2
  39. package/dist/{objectSpread2-60d1bd93.esm.js → objectSpread2-f1f0d77a.esm.js} +24 -1
  40. package/dist/{routeFromVal-64cba2a6.esm.js → routeFromVal-80976677.esm.js} +5 -155
  41. package/dist/{routeFromVal-4df1157a.cjs.dev.js → routeFromVal-a1e0a8be.cjs.dev.js} +3 -159
  42. package/dist/{routeFromVal-812be6ea.cjs.prod.js → routeFromVal-c4dace91.cjs.prod.js} +3 -159
  43. package/dist/{slicedToArray-ce613de6.cjs.prod.js → slicedToArray-0fc63719.cjs.prod.js} +1 -1
  44. package/dist/{slicedToArray-aa291011.esm.js → slicedToArray-5ff32315.esm.js} +1 -1
  45. package/dist/{slicedToArray-44036a76.cjs.dev.js → slicedToArray-ed812733.cjs.dev.js} +1 -1
  46. package/dist/{unsupportedIterableToArray-c8ab77c9.cjs.dev.js → unsupportedIterableToArray-1aadf9fb.cjs.prod.js} +1 -0
  47. package/dist/{unsupportedIterableToArray-0d2087a2.cjs.prod.js → unsupportedIterableToArray-20a9209f.cjs.dev.js} +1 -0
  48. package/dist/{unsupportedIterableToArray-5baabfdc.esm.js → unsupportedIterableToArray-f57eb659.esm.js} +1 -1
  49. package/dist/useHydrated-8e90c7fa.cjs.js +7 -0
  50. package/dist/useHydrated-8e90c7fa.cjs.prod.js +34 -0
  51. package/dist/useHydrated-afcdbb66.esm.js +26 -0
  52. package/dist/useHydrated-ff733777.cjs.dev.js +34 -0
  53. package/dist/valbuild-next.cjs.dev.js +7 -8
  54. package/dist/valbuild-next.cjs.prod.js +7 -8
  55. package/dist/valbuild-next.esm.js +7 -8
  56. package/dist/{version-b292025f.cjs.dev.js → version-284ab1bc.cjs.prod.js} +1 -1
  57. package/dist/{version-8bac9fbe.esm.js → version-41472ee7.esm.js} +1 -1
  58. package/dist/{version-bfb6bbc0.cjs.prod.js → version-bab8ec07.cjs.dev.js} +1 -1
  59. package/package.json +8 -8
  60. package/rsc/dist/valbuild-next-rsc.cjs.dev.js +243 -872
  61. package/rsc/dist/valbuild-next-rsc.cjs.prod.js +243 -872
  62. package/rsc/dist/valbuild-next-rsc.esm.js +243 -872
  63. package/server/dist/valbuild-next-server.cjs.dev.js +4 -5
  64. package/server/dist/valbuild-next-server.cjs.prod.js +4 -5
  65. package/server/dist/valbuild-next-server.esm.js +4 -5
  66. package/dist/ValApp-6c3da222.cjs.js +0 -7
  67. package/dist/ValCanvasBridge-134c3ae1.cjs.js +0 -7
  68. package/dist/ValNextProvider-35d0b521.cjs.js +0 -7
  69. package/dist/ValOverlayContext-1a45e03d.esm.js +0 -290
  70. package/dist/ValOverlayContext-262899b3.cjs.dev.js +0 -301
  71. package/dist/ValOverlayContext-405ca70c.cjs.js +0 -7
  72. package/dist/ValOverlayContext-405ca70c.cjs.prod.js +0 -301
  73. package/dist/ValVideo-dcd2b9f8.cjs.js +0 -7
  74. package/dist/defineProperty-8951f469.cjs.prod.js +0 -29
  75. package/dist/defineProperty-cca5affa.esm.js +0 -26
  76. package/dist/defineProperty-f90345d7.cjs.dev.js +0 -29
package/CHANGELOG.md CHANGED
@@ -1,5 +1,180 @@
1
1
  # @valbuild/next
2
2
 
3
+ ## 0.152.0
4
+
5
+ ### Patch Changes
6
+
7
+ - Updated dependencies [[`f4e0660`](https://github.com/valbuild/val/commit/f4e06601495dbee680a4b9000344f84cd3af717f), [`3bb76d7`](https://github.com/valbuild/val/commit/3bb76d74d82b499aa15023838d63018a70fd7ce7), [`08a3977`](https://github.com/valbuild/val/commit/08a39779dbe43702a72ae57cbf8cf29b14e64672)]:
8
+ - @valbuild/ui@0.152.0
9
+ - @valbuild/server@0.152.0
10
+ - @valbuild/shared@0.152.0
11
+ - @valbuild/mcp@0.152.0
12
+ - @valbuild/react@0.152.0
13
+ - @valbuild/language-server@0.152.0
14
+
15
+ ## 0.151.0
16
+
17
+ ### Minor Changes
18
+
19
+ - [#1006](https://github.com/valbuild/val/pull/1006) [`b0ad7f4`](https://github.com/valbuild/val/commit/b0ad7f496f2dc0384b8df847b1d77becf617b7bf) Thanks [@freekh](https://github.com/freekh)! - A draft page now catches up with an edit as soon as the server has it, instead
20
+ of on a timer.
21
+
22
+ - **The page settles faster, and without the 10 second fallback.** Content your
23
+ page reads on the server (a TanStack Start loader, a Next.js server component)
24
+ is refreshed when the editor's change has been saved, once per saved change.
25
+ It used to be refreshed the moment you typed — before the change was saved,
26
+ so the refresh often came back without it — and then again every 10 seconds
27
+ for half a minute in case it had. That safety refresh is gone, and so are the
28
+ extra requests it made while you edited. Another editor's change refreshes
29
+ the page too, once the server has it. While a deploy rolls out, a Studio of
30
+ the previous release (which never says it has saved) still refreshes the
31
+ page as each change arrives, as before.
32
+ - **Next.js: `ValProvider` takes an optional `draft` prop**, as
33
+ `@valbuild/tanstack`'s does: the editor's draft, read on the server for the
34
+ request. With it, the server renders the draft and the browser hydrates the
35
+ same thing, so a draft page no longer shows the published text first, and a
36
+ page that exists only as an unpublished change is found on the first render
37
+ instead of answering 404. Without it, nothing changes. See "The `draft` prop"
38
+ in the `@valbuild/next` README.
39
+ - **Next.js: `initValRsc` returns `fetchValDraft`**, which reads that draft:
40
+ pass `draft={await fetchValDraft()}` to `ValProvider` in your root layout. It
41
+ returns `null` unless the request is in draft mode, after one `draftMode()`
42
+ lookup and no other work, so visitors pay nothing and a static page stays
43
+ static. It reads the draft the way `@valbuild/tanstack/server`'s
44
+ `fetchValDraft` does and returns the same type, `ValDraft | null`, which
45
+ is now exported from `@valbuild/next` and `@valbuild/next/rsc` too.
46
+ - **`suspend` waits for the editor's changes properly.** With `suspend` on
47
+ `ValProvider`, a page could be told it had everything before the editor had
48
+ sent the pending change it needed, and render the published content first —
49
+ for a page that exists only as an unpublished change, a 404. It now waits
50
+ until the change is there.
51
+ - A draft page whose draft was discarded or published before the editor's
52
+ overlay or canvas connected now shows what the editor has, instead of keeping
53
+ the draft it was rendered with -- an edit inside a `.jsonValues()` entry
54
+ included.
55
+ - Turning draft mode on or off refreshes the page once. In development (React's
56
+ `StrictMode`) it could refresh twice, and Next.js could log "Cannot call
57
+ startTransition while rendering" while the page refreshed.
58
+
59
+ ### Patch Changes
60
+
61
+ - [#1006](https://github.com/valbuild/val/pull/1006) [`a325152`](https://github.com/valbuild/val/commit/a325152856a881faec84c112fcf226828739f563) Thanks [@freekh](https://github.com/freekh)! - **A draft page shows the right `.jsonValues()` entries, whichever reader reads them.**
62
+
63
+ - **Pending edits to an entry.** In draft mode, `fetchVal` of a whole
64
+ `.jsonValues()` record now shows the unpublished edits to its entries. It
65
+ used to show the published content of every entry, even one an editor had
66
+ just changed, while `fetchValKey` and `fetchValRoute` of the same entry
67
+ showed the edit. The entries a pending change touches are read from Val's
68
+ server; the others are loaded from your build, as before.
69
+ - **Entries published without a rebuild.** On a host that does not rebuild
70
+ the site after a publish, a draft page now shows the published entries
71
+ straight away -- in `fetchVal`, and in `useVal`, `useValKey` and
72
+ `useValRoute` alike. They used to show those entries as they were before
73
+ the publish, from the site's build, until it was rebuilt (and on TanStack
74
+ Start the server render showed the new content, then the page switched
75
+ back to the old). Val's server marks each entry a publish wrote, and the
76
+ readers and the Studio load a marked entry from the server.
77
+
78
+ - [#1006](https://github.com/valbuild/val/pull/1006) [`346e6fd`](https://github.com/valbuild/val/commit/346e6fdc8e242bf826ab66a729eacd9f8d4be1a6) Thanks [@freekh](https://github.com/freekh)! - **Draft pages read what was edited, not the whole site.** A page in draft
79
+ mode used to make Val's server read every module, apply every pending
80
+ change, and preview and validate the whole project on every request -- and
81
+ then ask again for each `.jsonValues()` entry it showed. Now there is one
82
+ copy of the draft per process, made once per change and shared by every
83
+ editor and every request:
84
+
85
+ - A module nobody edited costs nothing: the page reads its own build, as a
86
+ visitor's does.
87
+ - A request asks one cheap question -- has anything changed? -- once, and
88
+ the draft is only re-read when it has. An edit is applied once, to the
89
+ version before it, however many pages read it afterwards.
90
+ - `fetchVal`, `fetchValKey`, `fetchValRoute`, `fetchValRouteUrl` and
91
+ `fetchValDraft` (Next.js and TanStack Start alike) and Val's API routes
92
+ read that one copy, so a save through the API is seen by every reader at
93
+ once. Before, each kept its own, and a publish moved only the copy of the
94
+ server that handled it: in a host that keeps its content in memory, a
95
+ draft page read through `fetchValKey` or `fetchValRoute` went on showing
96
+ the content from before the publish.
97
+ - The MCP tools (`initValMcp`) read the same copy in local development and
98
+ on Val's hosting, where Val's options come from your config and the
99
+ environment. `initValMcp` takes no patch store or source files of its
100
+ own, so in a host that keeps its content in memory it keeps a copy of its
101
+ own, as before.
102
+ - If `initValServer` and `initValContent` (or `initValRsc`) are given
103
+ different options for the same `val.modules` (a different patch store,
104
+ say), they keep separate copies, and Val logs a warning saying which
105
+ options differ.
106
+
107
+ On a site of 20 MB of content a draft read went from about half a second per
108
+ request to well under a millisecond once the draft is in memory, and the
109
+ memory it holds grows with what was edited rather than with the size of the
110
+ site. Hosted sites in proxy mode ask the content service one small question
111
+ per request instead of reading every pending change; with a content service
112
+ that predates it, Val reads the pending changes as before.
113
+
114
+ `ValDraft` (what `fetchValDraft` returns and `<ValProvider draft>` takes)
115
+ has a new optional `versions` field, filled in by the server: the page uses
116
+ it to tell that what the Studio sends is what it already shows, without
117
+ comparing the content. Nothing to change in your app.
118
+
119
+ **Changed:** `PUT /api/val/sources/~` no longer computes previews or
120
+ validates the content (the Studio does both itself, and `/api/val/validate`
121
+ checks a module on request); its `validate_sources` and
122
+ `validate_binary_files` flags are accepted and ignored.
123
+
124
+ **Deprecated, and removed in the next release.** These stay for one release
125
+ only so that a Studio, a page or a server of the previous release keeps
126
+ working while a deploy rolls out. Nothing in this release uses them; if
127
+ your own code calls any of them, move off it now:
128
+
129
+ - `PUT /api/val/sources/~`, the whole route. This release's Studio reads
130
+ `GET /api/val/manifest` and `GET /api/val/modules/~<path>`, and the draft
131
+ readers and MCP read in-process.
132
+ - The `source` field of the overlay's `source-update` event and the canvas's
133
+ `sourceUpdate` message, and a page's support for an event that carries
134
+ only `source` (this release sends `read` beside it).
135
+ - `ValDraft.base`: not sent and not read; the type stays one release so
136
+ code written against the previous one still compiles.
137
+ - `/api/val/stat`'s `sourcesSha` and `schemaSha`: the next release's Studio
138
+ stops depending on them, and the release after it stops sending them.
139
+
140
+ - [#1006](https://github.com/valbuild/val/pull/1006) [`809873c`](https://github.com/valbuild/val/commit/809873cd7dd2c17e261b7e92716397a6bb4d6e56) Thanks [@freekh](https://github.com/freekh)! - Every content reader in `@valbuild/next` and `@valbuild/tanstack` — `fetchVal`,
141
+ `useVal`, the key and route readers, on the server and in the browser — now
142
+ loads content the same way, so they can no longer disagree about which content
143
+ wins. Nothing you call changes. What you may notice:
144
+
145
+ - `useValRoute` on a `.jsonValues()` router loads only the entry for the
146
+ current route. It used to load every entry of the record first.
147
+ `useValRouteUrl` and `fetchValRouteUrl` load none at all: a URL does not need
148
+ them.
149
+ - In development, an edited `*.val.json` entry shows its new content after a
150
+ hot reload. The hooks kept the entry they had loaded before it.
151
+ - Next.js: `useValKey` no longer shows the published entry of a nullable
152
+ `.jsonValues()` record that a draft has set to `null`, nor anything for an
153
+ entry named like a built-in object property (such as `toString`) that the
154
+ draft does not have.
155
+ - With `suspend` on `ValProvider`, `useValKey` now waits for draft mode and the
156
+ editor's changes too, as `useVal` and `useValRoute` already did.
157
+ - When one entry of a `.jsonValues()` record cannot be loaded, `useVal` logs
158
+ the error and renders the others, as `fetchVal` already did, instead of
159
+ failing the whole component.
160
+
161
+ - [#1006](https://github.com/valbuild/val/pull/1006) [`4dc1481`](https://github.com/valbuild/val/commit/4dc1481cfb7cad4072bdbeaeb51b2b2ad43a9f5d) Thanks [@freekh](https://github.com/freekh)! - The Studio now shows each module as your server has it, by version, with only your own unsaved edits on top.
162
+
163
+ - **Publishing is faster.** After a publish, or when your site serves content published without a build, the Studio used to download every module's content before it showed anything new. It now reads only the modules that changed, one at a time: in our measurements with a 1,000-entry `.jsonValues()` record, the Studio was ready again after a publish in about 35 ms instead of 300–800 ms.
164
+ - **No flicker of old content on a draft page.** For up to a minute after a deploy, a request can still reach the build before it; that build now says it has been replaced (when Val's content service can tell it), and the Studio asks again rather than taking its content for the current one. In local development the same holds after you change a `.val.ts`: an answer from the code before the change is no longer taken for the new code's, so a page in draft mode no longer shows the new text, then the old, then the new again.
165
+ - **Another editor's change appears as your server has it.** The Studio no longer replays other people's changes on top of the content it loaded with, so a change made against a newer deployment can no longer show up twice or out of order.
166
+ - **Less sent with every draft page.** A page in draft mode no longer embeds the whole published content of a site served without a rebuild for the Studio to start from; `ValDraft.base` is deprecated and no longer filled in.
167
+ - **When the editor opens on a page that already shows your changes,** the Studio no longer sends them to the page again.
168
+
169
+ - Updated dependencies [[`33c8b80`](https://github.com/valbuild/val/commit/33c8b80f877f1c3bec3cb61ef41dea9d2efcf908), [`213d635`](https://github.com/valbuild/val/commit/213d6359a1ec09cba1596ef03f415d3b5c0f2710), [`59faf33`](https://github.com/valbuild/val/commit/59faf332418af836617e09150fb89007e468394e), [`abf6148`](https://github.com/valbuild/val/commit/abf6148a255abe795620fede66006462bccb8322), [`04ed1f1`](https://github.com/valbuild/val/commit/04ed1f10b597a52822d32017597692f0e1062b7b), [`01772a5`](https://github.com/valbuild/val/commit/01772a5b36549d71f6b438ff17803dfcb64ce645), [`1f08b65`](https://github.com/valbuild/val/commit/1f08b6517adeac27fd9e43c7bf726976daefee3b), [`a325152`](https://github.com/valbuild/val/commit/a325152856a881faec84c112fcf226828739f563), [`b682509`](https://github.com/valbuild/val/commit/b682509b91dcd6e6aa2e1dfcedab0f259634c73e), [`f5110c9`](https://github.com/valbuild/val/commit/f5110c9aa2a0a6ff0586e9f0f2a29eb1baef557d), [`a806f7d`](https://github.com/valbuild/val/commit/a806f7de0c605145163c7f0babf389a5b5bf3ef3), [`04bae7e`](https://github.com/valbuild/val/commit/04bae7e54e6b191fc70f45e6f10bbce820b6069c), [`4fd35f3`](https://github.com/valbuild/val/commit/4fd35f321fe510cfb5b9b679ca14ce2b9e852d40), [`346e6fd`](https://github.com/valbuild/val/commit/346e6fdc8e242bf826ab66a729eacd9f8d4be1a6), [`b0ad7f4`](https://github.com/valbuild/val/commit/b0ad7f496f2dc0384b8df847b1d77becf617b7bf), [`3aff85e`](https://github.com/valbuild/val/commit/3aff85e9a40cb0879285b86fd41fa8167db1bb5e), [`809873c`](https://github.com/valbuild/val/commit/809873cd7dd2c17e261b7e92716397a6bb4d6e56), [`b41da31`](https://github.com/valbuild/val/commit/b41da31a26b3236ccd55c02108c56422d8d91f5e), [`560abd9`](https://github.com/valbuild/val/commit/560abd9df36e52e63b6592b03a8040396320df00), [`be276e7`](https://github.com/valbuild/val/commit/be276e76f5849fcc421398abdb7e114f3de4d3e8), [`e30da7d`](https://github.com/valbuild/val/commit/e30da7d9bca5d5773aa287e8b4c16a01e757ff9a), [`66d487f`](https://github.com/valbuild/val/commit/66d487f3662164a9a167ec660afc6d12b441aa22), [`4dc1481`](https://github.com/valbuild/val/commit/4dc1481cfb7cad4072bdbeaeb51b2b2ad43a9f5d), [`4edd384`](https://github.com/valbuild/val/commit/4edd384cf04a25836df77aae6d88378f8750a761)]:
170
+ - @valbuild/ui@0.151.0
171
+ - @valbuild/server@0.151.0
172
+ - @valbuild/shared@0.151.0
173
+ - @valbuild/core@0.151.0
174
+ - @valbuild/react@0.151.0
175
+ - @valbuild/mcp@0.151.0
176
+ - @valbuild/language-server@0.151.0
177
+
3
178
  ## 0.150.23
4
179
 
5
180
  ### Patch Changes
package/README.md CHANGED
@@ -43,6 +43,8 @@
43
43
  - [Installation](#installation)
44
44
  - [Getting started](#getting-started)
45
45
  - [Previewing unpublished pages](#previewing-unpublished-pages)
46
+ - [The `draft` prop](#the-draft-prop)
47
+ - [Refreshes in draft mode](#refreshes-in-draft-mode)
46
48
  - [Schema types](#schema-types):
47
49
  - [String](#string)
48
50
  - [Number](#number)
@@ -280,7 +282,86 @@ after hydration, and the render before that resolves against published content.
280
282
  A page that calls `notFound()` at that point cannot recover, since the response
281
283
  has already been sent. Reloading the page in the editor works around it. Pages
282
284
  that read content for a route they already have — the common case, editing an
283
- existing page — are not affected.
285
+ existing page — are not affected. The `draft` prop below is what closes it.
286
+
287
+ ## The `draft` prop
288
+
289
+ `ValProvider` takes an optional `draft`: the editor's draft, read on the server
290
+ for this request — the source of every module the draft changes, in the same
291
+ shape `@valbuild/tanstack`'s `fetchValDraft` returns. With it, the provider's
292
+ store holds the draft on the server and in the browser alike, so a client
293
+ component's server render and its hydration render are the draft from the
294
+ first byte: no published text first and the draft a moment later, and a route
295
+ that exists only in an unpublished change is found on the render that decides
296
+ whether the page is a 404.
297
+
298
+ Read it with `fetchValDraft`, which `initValRsc` returns beside `fetchVal`:
299
+
300
+ ```ts
301
+ // ./val/rsc.ts
302
+ import "server-only";
303
+ import { initValRsc } from "@valbuild/next/rsc";
304
+ import { config } from "../val.config";
305
+ import valModules from "../val.modules";
306
+ import { cookies, draftMode, headers } from "next/headers";
307
+
308
+ const {
309
+ fetchValStega: fetchVal,
310
+ fetchValRouteStega: fetchValRoute,
311
+ fetchValDraft,
312
+ } = initValRsc(config, valModules, { draftMode, headers, cookies });
313
+
314
+ export { fetchVal, fetchValRoute, fetchValDraft };
315
+ ```
316
+
317
+ and pass what it returns from the root layout, a Server Component:
318
+
319
+ ```tsx
320
+ // ./app/layout.tsx
321
+ import { ValProvider } from "@valbuild/next";
322
+ import { config } from "../val.config";
323
+ import { fetchValDraft } from "../val/rsc";
324
+
325
+ export default async function RootLayout({
326
+ children,
327
+ }: {
328
+ children: React.ReactNode;
329
+ }) {
330
+ return (
331
+ <html lang="en">
332
+ <body>
333
+ <ValProvider config={config} suspend draft={await fetchValDraft()}>
334
+ {children}
335
+ </ValProvider>
336
+ </body>
337
+ </html>
338
+ );
339
+ }
340
+ ```
341
+
342
+ `fetchValDraft` returns `null` unless the request is in draft mode, after one
343
+ `draftMode()` lookup and no read: a visitor pays nothing for it, and
344
+ `draftMode()` does not make a static route dynamic. In draft mode it reads the
345
+ request's cookies (which does) and returns the modules the draft changes, from
346
+ the same read every `fetchVal` in that request shares. It is also `null` when
347
+ the editor's session has expired, or the draft cannot be read (logged): the
348
+ page is then rendered as published, as it would be without it. The type is
349
+ `ValDraft`, exported from `@valbuild/next/rsc`.
350
+
351
+ The prop is optional and additive: without it (or with `null`), the provider
352
+ behaves exactly as before. It is read once, when the provider mounts. The edit
353
+ tags (what makes content click-to-edit) are left out of the server's HTML and
354
+ the hydration render, and added by the render right after, so the two agree.
355
+
356
+ ## Refreshes in draft mode
357
+
358
+ Server components only change when the route is refreshed, and only show an
359
+ edit once the server has it. So in draft mode the page calls `router.refresh()`
360
+ when the editor says the server has confirmed an edit — once per confirmed
361
+ change, never on a timer — rather than when the edit is typed, which raced the
362
+ write and came back without it. Client components (`useVal` and friends) show an
363
+ edit as it is typed, from the editor. `disableRefresh` on `ValProvider` turns
364
+ the refreshes off.
284
365
 
285
366
  # Formatting published content
286
367