@valbuild/next 0.150.22 → 0.151.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.
- package/CHANGELOG.md +174 -0
- package/README.md +82 -1
- package/client/dist/valbuild-next-client.cjs.dev.js +123 -256
- package/client/dist/valbuild-next-client.cjs.prod.js +123 -256
- package/client/dist/valbuild-next-client.esm.js +122 -255
- package/dist/{ValApp-a88a9ded.esm.js → ValApp-69cd599c.esm.js} +3 -3
- package/dist/{ValApp-c718d1a6.cjs.dev.js → ValApp-826dca6c.cjs.dev.js} +3 -3
- package/dist/ValApp-866089f6.cjs.js +7 -0
- package/dist/{ValApp-6c3da222.cjs.prod.js → ValApp-866089f6.cjs.prod.js} +3 -3
- package/dist/{ValCanvasBridge-9d221d32.cjs.dev.js → ValCanvasBridge-4b81f653.cjs.dev.js} +46 -13
- package/dist/ValCanvasBridge-6f568f1d.cjs.js +7 -0
- package/dist/{ValCanvasBridge-134c3ae1.cjs.prod.js → ValCanvasBridge-6f568f1d.cjs.prod.js} +46 -13
- package/dist/{ValCanvasBridge-4a5ef73c.esm.js → ValCanvasBridge-badc186b.esm.js} +46 -13
- package/dist/ValNextProvider-41d622a7.cjs.js +7 -0
- package/dist/{ValNextProvider-35d0b521.cjs.prod.js → ValNextProvider-41d622a7.cjs.prod.js} +124 -234
- package/dist/{ValNextProvider-a85a1d33.cjs.dev.js → ValNextProvider-4b9bcfc0.cjs.dev.js} +124 -234
- package/dist/{ValNextProvider-df6f351e.esm.js → ValNextProvider-745ed99e.esm.js} +124 -234
- package/dist/ValOverlayContext-0c29b6a7.cjs.dev.js +51 -0
- package/dist/ValOverlayContext-0f51d111.cjs.js +7 -0
- package/dist/ValOverlayContext-0f51d111.cjs.prod.js +51 -0
- package/dist/ValOverlayContext-178db68e.esm.js +37 -0
- package/dist/ValVideo-02f43a7c.cjs.js +7 -0
- package/dist/{ValVideo-dcd2b9f8.cjs.prod.js → ValVideo-02f43a7c.cjs.prod.js} +1 -2
- package/dist/{ValVideo-6e410ad8.cjs.dev.js → ValVideo-15e5c4fa.cjs.dev.js} +1 -2
- package/dist/{ValVideo-d377f06e.esm.js → ValVideo-8acf31b6.esm.js} +1 -2
- package/dist/{createForOfIteratorHelper-d4afcad8.cjs.prod.js → createForOfIteratorHelper-8459fbc7.cjs.prod.js} +1 -1
- package/dist/{createForOfIteratorHelper-5758a730.esm.js → createForOfIteratorHelper-9209e9dd.esm.js} +1 -1
- package/dist/{createForOfIteratorHelper-0445603c.cjs.dev.js → createForOfIteratorHelper-9c6aa3c7.cjs.dev.js} +1 -1
- package/dist/declarations/src/ValProvider.d.ts +1 -0
- package/dist/declarations/src/client/initValClient.d.ts +25 -3
- package/dist/declarations/src/external_exempt_from_val_quickjs.d.ts +1 -0
- package/dist/declarations/src/rsc/index.d.ts +1 -0
- package/dist/declarations/src/rsc/initValRsc.d.ts +56 -118
- package/dist/declarations/src/server/initValServer.d.ts +2 -1
- package/dist/{fallbackColors-149dfbc9.esm.js → fallbackColors-0d915c59.esm.js} +1 -1
- package/dist/{fallbackColors-080c1bbc.cjs.dev.js → fallbackColors-38f01ad2.cjs.dev.js} +1 -1
- package/dist/{fallbackColors-e1d73b36.cjs.prod.js → fallbackColors-d9a7b81e.cjs.prod.js} +1 -1
- package/dist/{objectSpread2-13f847a9.cjs.prod.js → objectSpread2-469273e9.cjs.prod.js} +25 -2
- package/dist/{objectSpread2-58024783.cjs.dev.js → objectSpread2-58726b14.cjs.dev.js} +25 -2
- package/dist/{objectSpread2-60d1bd93.esm.js → objectSpread2-f1f0d77a.esm.js} +24 -1
- package/dist/{routeFromVal-64cba2a6.esm.js → routeFromVal-80976677.esm.js} +5 -155
- package/dist/{routeFromVal-4df1157a.cjs.dev.js → routeFromVal-a1e0a8be.cjs.dev.js} +3 -159
- package/dist/{routeFromVal-812be6ea.cjs.prod.js → routeFromVal-c4dace91.cjs.prod.js} +3 -159
- package/dist/{slicedToArray-ce613de6.cjs.prod.js → slicedToArray-0fc63719.cjs.prod.js} +1 -1
- package/dist/{slicedToArray-aa291011.esm.js → slicedToArray-5ff32315.esm.js} +1 -1
- package/dist/{slicedToArray-44036a76.cjs.dev.js → slicedToArray-ed812733.cjs.dev.js} +1 -1
- package/dist/{unsupportedIterableToArray-c8ab77c9.cjs.dev.js → unsupportedIterableToArray-1aadf9fb.cjs.prod.js} +1 -0
- package/dist/{unsupportedIterableToArray-0d2087a2.cjs.prod.js → unsupportedIterableToArray-20a9209f.cjs.dev.js} +1 -0
- package/dist/{unsupportedIterableToArray-5baabfdc.esm.js → unsupportedIterableToArray-f57eb659.esm.js} +1 -1
- package/dist/useHydrated-8e90c7fa.cjs.js +7 -0
- package/dist/useHydrated-8e90c7fa.cjs.prod.js +34 -0
- package/dist/useHydrated-afcdbb66.esm.js +26 -0
- package/dist/useHydrated-ff733777.cjs.dev.js +34 -0
- package/dist/valbuild-next.cjs.dev.js +7 -8
- package/dist/valbuild-next.cjs.prod.js +7 -8
- package/dist/valbuild-next.esm.js +7 -8
- package/dist/{version-18c11a6d.cjs.prod.js → version-114c45b6.cjs.prod.js} +1 -1
- package/dist/{version-70b7333d.cjs.dev.js → version-cc1bc4e5.cjs.dev.js} +1 -1
- package/dist/{version-a2218191.esm.js → version-d8f64e54.esm.js} +1 -1
- package/package.json +8 -8
- package/rsc/dist/valbuild-next-rsc.cjs.dev.js +243 -872
- package/rsc/dist/valbuild-next-rsc.cjs.prod.js +243 -872
- package/rsc/dist/valbuild-next-rsc.esm.js +243 -872
- package/server/dist/valbuild-next-server.cjs.dev.js +4 -5
- package/server/dist/valbuild-next-server.cjs.prod.js +4 -5
- package/server/dist/valbuild-next-server.esm.js +4 -5
- package/dist/ValApp-6c3da222.cjs.js +0 -7
- package/dist/ValCanvasBridge-134c3ae1.cjs.js +0 -7
- package/dist/ValNextProvider-35d0b521.cjs.js +0 -7
- package/dist/ValOverlayContext-1a45e03d.esm.js +0 -290
- package/dist/ValOverlayContext-262899b3.cjs.dev.js +0 -301
- package/dist/ValOverlayContext-405ca70c.cjs.js +0 -7
- package/dist/ValOverlayContext-405ca70c.cjs.prod.js +0 -301
- package/dist/ValVideo-dcd2b9f8.cjs.js +0 -7
- package/dist/defineProperty-8951f469.cjs.prod.js +0 -29
- package/dist/defineProperty-cca5affa.esm.js +0 -26
- package/dist/defineProperty-f90345d7.cjs.dev.js +0 -29
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,179 @@
|
|
|
1
1
|
# @valbuild/next
|
|
2
2
|
|
|
3
|
+
## 0.151.0
|
|
4
|
+
|
|
5
|
+
### Minor Changes
|
|
6
|
+
|
|
7
|
+
- [#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
|
|
8
|
+
of on a timer.
|
|
9
|
+
|
|
10
|
+
- **The page settles faster, and without the 10 second fallback.** Content your
|
|
11
|
+
page reads on the server (a TanStack Start loader, a Next.js server component)
|
|
12
|
+
is refreshed when the editor's change has been saved, once per saved change.
|
|
13
|
+
It used to be refreshed the moment you typed — before the change was saved,
|
|
14
|
+
so the refresh often came back without it — and then again every 10 seconds
|
|
15
|
+
for half a minute in case it had. That safety refresh is gone, and so are the
|
|
16
|
+
extra requests it made while you edited. Another editor's change refreshes
|
|
17
|
+
the page too, once the server has it. While a deploy rolls out, a Studio of
|
|
18
|
+
the previous release (which never says it has saved) still refreshes the
|
|
19
|
+
page as each change arrives, as before.
|
|
20
|
+
- **Next.js: `ValProvider` takes an optional `draft` prop**, as
|
|
21
|
+
`@valbuild/tanstack`'s does: the editor's draft, read on the server for the
|
|
22
|
+
request. With it, the server renders the draft and the browser hydrates the
|
|
23
|
+
same thing, so a draft page no longer shows the published text first, and a
|
|
24
|
+
page that exists only as an unpublished change is found on the first render
|
|
25
|
+
instead of answering 404. Without it, nothing changes. See "The `draft` prop"
|
|
26
|
+
in the `@valbuild/next` README.
|
|
27
|
+
- **Next.js: `initValRsc` returns `fetchValDraft`**, which reads that draft:
|
|
28
|
+
pass `draft={await fetchValDraft()}` to `ValProvider` in your root layout. It
|
|
29
|
+
returns `null` unless the request is in draft mode, after one `draftMode()`
|
|
30
|
+
lookup and no other work, so visitors pay nothing and a static page stays
|
|
31
|
+
static. It reads the draft the way `@valbuild/tanstack/server`'s
|
|
32
|
+
`fetchValDraft` does and returns the same type, `ValDraft | null`, which
|
|
33
|
+
is now exported from `@valbuild/next` and `@valbuild/next/rsc` too.
|
|
34
|
+
- **`suspend` waits for the editor's changes properly.** With `suspend` on
|
|
35
|
+
`ValProvider`, a page could be told it had everything before the editor had
|
|
36
|
+
sent the pending change it needed, and render the published content first —
|
|
37
|
+
for a page that exists only as an unpublished change, a 404. It now waits
|
|
38
|
+
until the change is there.
|
|
39
|
+
- A draft page whose draft was discarded or published before the editor's
|
|
40
|
+
overlay or canvas connected now shows what the editor has, instead of keeping
|
|
41
|
+
the draft it was rendered with -- an edit inside a `.jsonValues()` entry
|
|
42
|
+
included.
|
|
43
|
+
- Turning draft mode on or off refreshes the page once. In development (React's
|
|
44
|
+
`StrictMode`) it could refresh twice, and Next.js could log "Cannot call
|
|
45
|
+
startTransition while rendering" while the page refreshed.
|
|
46
|
+
|
|
47
|
+
### Patch Changes
|
|
48
|
+
|
|
49
|
+
- [#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.**
|
|
50
|
+
|
|
51
|
+
- **Pending edits to an entry.** In draft mode, `fetchVal` of a whole
|
|
52
|
+
`.jsonValues()` record now shows the unpublished edits to its entries. It
|
|
53
|
+
used to show the published content of every entry, even one an editor had
|
|
54
|
+
just changed, while `fetchValKey` and `fetchValRoute` of the same entry
|
|
55
|
+
showed the edit. The entries a pending change touches are read from Val's
|
|
56
|
+
server; the others are loaded from your build, as before.
|
|
57
|
+
- **Entries published without a rebuild.** On a host that does not rebuild
|
|
58
|
+
the site after a publish, a draft page now shows the published entries
|
|
59
|
+
straight away -- in `fetchVal`, and in `useVal`, `useValKey` and
|
|
60
|
+
`useValRoute` alike. They used to show those entries as they were before
|
|
61
|
+
the publish, from the site's build, until it was rebuilt (and on TanStack
|
|
62
|
+
Start the server render showed the new content, then the page switched
|
|
63
|
+
back to the old). Val's server marks each entry a publish wrote, and the
|
|
64
|
+
readers and the Studio load a marked entry from the server.
|
|
65
|
+
|
|
66
|
+
- [#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
|
|
67
|
+
mode used to make Val's server read every module, apply every pending
|
|
68
|
+
change, and preview and validate the whole project on every request -- and
|
|
69
|
+
then ask again for each `.jsonValues()` entry it showed. Now there is one
|
|
70
|
+
copy of the draft per process, made once per change and shared by every
|
|
71
|
+
editor and every request:
|
|
72
|
+
|
|
73
|
+
- A module nobody edited costs nothing: the page reads its own build, as a
|
|
74
|
+
visitor's does.
|
|
75
|
+
- A request asks one cheap question -- has anything changed? -- once, and
|
|
76
|
+
the draft is only re-read when it has. An edit is applied once, to the
|
|
77
|
+
version before it, however many pages read it afterwards.
|
|
78
|
+
- `fetchVal`, `fetchValKey`, `fetchValRoute`, `fetchValRouteUrl` and
|
|
79
|
+
`fetchValDraft` (Next.js and TanStack Start alike) and Val's API routes
|
|
80
|
+
read that one copy, so a save through the API is seen by every reader at
|
|
81
|
+
once. Before, each kept its own, and a publish moved only the copy of the
|
|
82
|
+
server that handled it: in a host that keeps its content in memory, a
|
|
83
|
+
draft page read through `fetchValKey` or `fetchValRoute` went on showing
|
|
84
|
+
the content from before the publish.
|
|
85
|
+
- The MCP tools (`initValMcp`) read the same copy in local development and
|
|
86
|
+
on Val's hosting, where Val's options come from your config and the
|
|
87
|
+
environment. `initValMcp` takes no patch store or source files of its
|
|
88
|
+
own, so in a host that keeps its content in memory it keeps a copy of its
|
|
89
|
+
own, as before.
|
|
90
|
+
- If `initValServer` and `initValContent` (or `initValRsc`) are given
|
|
91
|
+
different options for the same `val.modules` (a different patch store,
|
|
92
|
+
say), they keep separate copies, and Val logs a warning saying which
|
|
93
|
+
options differ.
|
|
94
|
+
|
|
95
|
+
On a site of 20 MB of content a draft read went from about half a second per
|
|
96
|
+
request to well under a millisecond once the draft is in memory, and the
|
|
97
|
+
memory it holds grows with what was edited rather than with the size of the
|
|
98
|
+
site. Hosted sites in proxy mode ask the content service one small question
|
|
99
|
+
per request instead of reading every pending change; with a content service
|
|
100
|
+
that predates it, Val reads the pending changes as before.
|
|
101
|
+
|
|
102
|
+
`ValDraft` (what `fetchValDraft` returns and `<ValProvider draft>` takes)
|
|
103
|
+
has a new optional `versions` field, filled in by the server: the page uses
|
|
104
|
+
it to tell that what the Studio sends is what it already shows, without
|
|
105
|
+
comparing the content. Nothing to change in your app.
|
|
106
|
+
|
|
107
|
+
**Changed:** `PUT /api/val/sources/~` no longer computes previews or
|
|
108
|
+
validates the content (the Studio does both itself, and `/api/val/validate`
|
|
109
|
+
checks a module on request); its `validate_sources` and
|
|
110
|
+
`validate_binary_files` flags are accepted and ignored.
|
|
111
|
+
|
|
112
|
+
**Deprecated, and removed in the next release.** These stay for one release
|
|
113
|
+
only so that a Studio, a page or a server of the previous release keeps
|
|
114
|
+
working while a deploy rolls out. Nothing in this release uses them; if
|
|
115
|
+
your own code calls any of them, move off it now:
|
|
116
|
+
|
|
117
|
+
- `PUT /api/val/sources/~`, the whole route. This release's Studio reads
|
|
118
|
+
`GET /api/val/manifest` and `GET /api/val/modules/~<path>`, and the draft
|
|
119
|
+
readers and MCP read in-process.
|
|
120
|
+
- The `source` field of the overlay's `source-update` event and the canvas's
|
|
121
|
+
`sourceUpdate` message, and a page's support for an event that carries
|
|
122
|
+
only `source` (this release sends `read` beside it).
|
|
123
|
+
- `ValDraft.base`: not sent and not read; the type stays one release so
|
|
124
|
+
code written against the previous one still compiles.
|
|
125
|
+
- `/api/val/stat`'s `sourcesSha` and `schemaSha`: the next release's Studio
|
|
126
|
+
stops depending on them, and the release after it stops sending them.
|
|
127
|
+
|
|
128
|
+
- [#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`,
|
|
129
|
+
`useVal`, the key and route readers, on the server and in the browser — now
|
|
130
|
+
loads content the same way, so they can no longer disagree about which content
|
|
131
|
+
wins. Nothing you call changes. What you may notice:
|
|
132
|
+
|
|
133
|
+
- `useValRoute` on a `.jsonValues()` router loads only the entry for the
|
|
134
|
+
current route. It used to load every entry of the record first.
|
|
135
|
+
`useValRouteUrl` and `fetchValRouteUrl` load none at all: a URL does not need
|
|
136
|
+
them.
|
|
137
|
+
- In development, an edited `*.val.json` entry shows its new content after a
|
|
138
|
+
hot reload. The hooks kept the entry they had loaded before it.
|
|
139
|
+
- Next.js: `useValKey` no longer shows the published entry of a nullable
|
|
140
|
+
`.jsonValues()` record that a draft has set to `null`, nor anything for an
|
|
141
|
+
entry named like a built-in object property (such as `toString`) that the
|
|
142
|
+
draft does not have.
|
|
143
|
+
- With `suspend` on `ValProvider`, `useValKey` now waits for draft mode and the
|
|
144
|
+
editor's changes too, as `useVal` and `useValRoute` already did.
|
|
145
|
+
- When one entry of a `.jsonValues()` record cannot be loaded, `useVal` logs
|
|
146
|
+
the error and renders the others, as `fetchVal` already did, instead of
|
|
147
|
+
failing the whole component.
|
|
148
|
+
|
|
149
|
+
- [#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.
|
|
150
|
+
|
|
151
|
+
- **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.
|
|
152
|
+
- **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.
|
|
153
|
+
- **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.
|
|
154
|
+
- **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.
|
|
155
|
+
- **When the editor opens on a page that already shows your changes,** the Studio no longer sends them to the page again.
|
|
156
|
+
|
|
157
|
+
- 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)]:
|
|
158
|
+
- @valbuild/ui@0.151.0
|
|
159
|
+
- @valbuild/server@0.151.0
|
|
160
|
+
- @valbuild/shared@0.151.0
|
|
161
|
+
- @valbuild/core@0.151.0
|
|
162
|
+
- @valbuild/react@0.151.0
|
|
163
|
+
- @valbuild/mcp@0.151.0
|
|
164
|
+
- @valbuild/language-server@0.151.0
|
|
165
|
+
|
|
166
|
+
## 0.150.23
|
|
167
|
+
|
|
168
|
+
### Patch Changes
|
|
169
|
+
|
|
170
|
+
- Updated dependencies [[`41b73af`](https://github.com/valbuild/val/commit/41b73af5db02ec2fef3f8b3884be453712d9ada3), [`e46c34a`](https://github.com/valbuild/val/commit/e46c34a7eb6080e2286a85cc70f1e98d3989b8a9), [`1970507`](https://github.com/valbuild/val/commit/19705071884f8dddabd0a1319a8a4bdb4b9cdfed)]:
|
|
171
|
+
- @valbuild/ui@0.150.23
|
|
172
|
+
- @valbuild/react@0.150.23
|
|
173
|
+
- @valbuild/server@0.150.23
|
|
174
|
+
- @valbuild/language-server@0.150.23
|
|
175
|
+
- @valbuild/mcp@0.150.23
|
|
176
|
+
|
|
3
177
|
## 0.150.22
|
|
4
178
|
|
|
5
179
|
### 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
|
|