102 Commits
Author SHA1 Message Date
Michael St.ClaireandAlexander Medvednikov 640dda22aa veb, tools: live reload over server-sent events, keeping page state (#30208)
* tools: make `v watch` build veb apps before restarting them

- Watch `templates/` and its subdirectories in veb projects. Templates are
  compiled in, but the compiler does not report them, so a change to
  `templates/layout/header.html` never triggered a rebuild.
- For veb apps, build the new executable while the old server keeps
  serving, and swap them only when the build succeeds, so the app is down
  only for the restart. A failed build leaves the old server running. A
  change during a build cancels it and starts a new one, after a 150 ms
  debounce. `--no-build-first` restores the previous behaviour.
- Write the build status (`building`, `failed` with the compiler output, or
  `ok`) to a file named by VEB_LIVERELOAD_STATUS in the app's environment,
  for veb's live reload. Print how long each build took.
- Stop the build and the program on SIGTERM and SIGHUP, as on Ctrl-C. They
  run in their own process groups, so they kept running (and kept their
  port) after `v watch` was terminated.

* veb: live reload over server-sent events, keeping page state

With `-d veb_livereload`:
- Replace the 250 ms polling with one Server-Sent Events stream per page,
  held in a shared hub (no thread per tab), capped by
  `-d veb_livereload_max_streams` (default 32). A keepalive ping every 15 s
  drops closed tabs.
- After a restart, fetch the page again and morph the DOM in place, keeping
  scroll position, focus, typed form values and page JS state. Pages from a
  POST, failed fetches and non-HTML answers reload instead.
- Follow the files of a StaticHandler: a changed stylesheet is swapped in
  place, other files update the page, with no rebuild.
- Relay the build status written by `v watch` (VEB_LIVERELOAD_STATUS): a
  toast for rebuilding/updated, and a panel with the compiler output when a
  build fails. `-d veb_livereload_no_toast` hides them.
- Reconnect every 250 ms; `-d veb_livereload_retry_max_ms` lets it back off.
- Keep the polling script behind `-d veb_livereload_polling`, for HTTPS apps
  and for proxies that block long-lived connections, with its interval set
  by `-d veb_livereload_poll_ms`. Deprecate the unused
  `Context.livereload_poll_interval_ms`, which could never be set.

* examples, docs: update the veb live reload instructions

- examples/vwatch/web_server: put `-d veb_livereload` after `watch` (the
  order before `watch` is currently dropped, see #30199), describe the new
  live reload, and drop `--only-watch=*.v,*.html,*.css,*.js`, which is the
  default for veb projects.
- v-veb skill: live reload is enabled by `-d veb_livereload` and applies to
  any HTML response ending with `</html>`, not only to `$veb.html()` in
  debug builds.
- veb blog tutorial: suggest `v watch -d veb_livereload run blog.v`, so the
  open page updates too.

* veb: reload changed scripts and page resources

* veb: preserve typed values on their original form controls

---------

Co-authored-by: Alexander Medvednikov <alexander@medvednikov.com>
2026-10-12 00:14:46 +03:00
Alexander Medvednikov ce02c5f92d fmt: migrate deprecated json module usage to json2 (#27804) 2026-07-16 23:52:27 +03:00
Alexander Medvednikov c8fcb5956e all: remove all vweb references 2026-04-20 12:46:55 +03:00
Alexander Medvednikov b6314dba31 all: add thin bindings for sled database (nosql) (fixes #3850) 2026-04-17 23:40:03 +03:00
Alexander Medvednikov c60158fc93 doc: update "building a simple web blog with veb" tutorial for fetching data with ORM (fixes #24708) 2026-04-17 23:39:17 +03:00
00gh ecc946002a tutorials: remove newline in the example for c2v's cc compilation to doomv (#26200) 2025-12-29 07:06:02 +02:00
jpeg729 aaf3d3315d tutorials: fix compilation errors in Building a simple web blog with Veb (#24631) 2025-06-01 17:07:44 +03:00
Alexander Medvednikov 8683e634ee veb: deprecate vweb (part 2); move all vweb examples to veb 2025-03-02 14:37:20 +03:00
Alexander Medvednikov f83af8a1a2 veb: deprecate vweb (part 1); update the blog tutorial 2025-03-01 03:34:16 +03:00
Delyan Angelov 8241f22116 ci: use -silent in more jobs that produce a lot of OK lines normally (for test-cleancode, test-self, build-examples, build-tools) 2025-02-24 11:23:59 +02:00
yuyi c51d30bf53 fmt: fix alignment of struct init fields (#22025) 2024-08-11 09:11:24 +03:00
yuyi ddb6685d8a fmt: fix and simplify align of struct fields (#21995) 2024-08-05 20:23:39 +03:00
Alexander Medvednikov 399af6768d gg: fn (data voidptr, e &Event) for events, allows methods 2023-11-25 01:19:39 +03:00
Alexander Medvednikov fc69b2fdb1 tutorials: minor vweb blog updates 2023-11-25 00:49:22 +03:00
Turiiya c80515465e docs: update deprecated blockquote highlight syntax (#19974) 2023-11-23 13:33:33 +02:00
Delyan Angelov f7b9e4eafd vfmt: automate transition from the old [attribute] to the new @[attribute] syntax (#19912) 2023-11-17 17:43:29 +02:00
Turiiya b347f546f2 all: update remaining deprecated attr syntax (#19908) 2023-11-17 12:03:51 +02:00
Joe C 757929392e all: update attributes to use new syntax 2023-11-15 16:16:01 +11:00
Delyan Angelov e3ade704cb tools: remove remaining references to vlib/sqlite, vlib/mysql, vlib/pg (and make v test-cleancode fail *loudly*, when a folder is missing, regression after a421e485f). 2023-08-03 23:10:02 +03:00
sigmaSd 2266ccecf3 readme: update web tutorial, fix code (#18989) 2023-07-28 12:36:46 +03:00
Turiiya af4e113f6c vweb: use <head> instead of <header> in the html templates (#18516) 2023-06-22 11:11:02 +03:00
DrainGangScholar 691bc0e7b2 readme: add a missing cd (#18368) 2023-06-08 01:53:39 +03:00
walking devel 8452644ec3 orm: enforce that queries always return a Result, a query-resulting array can be used as a V array in place. (#17871) 2023-04-04 08:23:06 +03:00
Makhnev Petr c8c70de87d docs: unify format of notes (#17294) 2023-02-13 10:29:02 +02:00
yuyi 64558df764 vlib: move the mysql/sqlite/pg/mssql modules under vlib/db (#16820) 2023-01-13 17:02:32 +02:00
Ted Stoychev e1896ffd5b tutorials: fix a broken link (#16333) 2022-11-05 08:13:00 +03:00
Ted Stoychev 5933ab7158 docs: add syntax highlighting to a code snippet in the tutorials (#16331) 2022-11-04 17:01:25 +02:00
Grantley Cullar 37b03e57b4 tutorials: fix typos (#16098) 2022-10-19 12:20:11 +03:00
Alwin Arrasyid 6ed69289a8 tutorials: remove unnecessary json.encode (#15464) 2022-08-19 19:27:26 +03:00
Alexander Medvednikov 8736f26a1c tutorials: simplify new_article() a bit 2022-08-16 22:20:03 +03:00
Alexander Medvednikov 78c527b243 tutorials: improve c2v tutorial a bit 2022-06-23 02:45:14 +03:00
Delyan Angelov a7108ff05c docs: use the actual most recent output of c2v in the example 2022-06-23 01:39:39 +03:00
Delyan Angelov b8d9bfec16 docs: fix C primes example in the tutorials (fixes c2v translation on linux) 2022-06-23 01:35:45 +03:00
Delyan Angelov 436081a9f5 ci: fix v check-md tutorials/ 2022-06-23 01:30:22 +03:00
Delyan Angelov 1b87a4770c tutorials: rename the folder containing spaces, to fix git checkouts on windows 2022-06-23 01:08:07 +03:00
Delyan Angelov 856270cac2 tutorials: restore the old tutorials/building_a_simple_web_blog_with_vweb/ folder. 2022-06-23 00:11:59 +03:00
Alexander Medvednikov fe673e7963 tutorials: rename vweb tutorial 2022-06-22 22:48:40 +03:00
Alexander Medvednikov ae2183043b tutorials: c2v 2022-06-22 22:47:43 +03:00
Daniel Däschle d679146a80 fmt: remove space in front of ? and ! (#14366) 2022-05-13 06:56:21 +03:00
Benjamin Thomas 48eb40cd2c doc: suggest a basic auto-reload setup (#14216) 2022-04-29 20:57:04 +03:00
Carlos Esquerdo Bernat 6d62574e7f tutorials: fix argument type (#12182) 2021-10-15 02:24:22 +03:00
Alexander Medvednikov 555e8cada6 tutorials: update the vweb tutorial with the new form parsing syntax 2021-10-12 07:17:49 +03:00
srp-at-ah 227d12f1ac tutorial: fix missing & in README.md (#11363) 2021-09-02 09:30:05 +03:00
Alexander Medvednikov a39962a6b9 tutorials: fix blog.v code formatting 2021-08-03 16:13:41 +03:00
Alexander Medvednikov 80976e640c vweb: remove init_server() from all examples, tutorials, and tests 2021-08-03 16:03:16 +03:00
Delyan Angelov 9315154201 ci: workaround -autofree codegen bug with nested fn calls on macos 2021-07-22 11:02:17 +03:00
Hank G be7c3965a9 doc: update blog tutorial to updated syntax and instructions (#10577) 2021-07-21 17:33:16 +03:00
Georg Hartmann b80dcafc24 tutorials: always add the filename as first comment in example files (#10594) 2021-06-28 08:34:53 +03:00
Delyan Angelov 6450fda938 ci: fix compiling blog/, *and* comptime_if_is_test.v. Add vweb_app_test.v . 2021-05-11 13:59:08 +03:00
Delyan Angelov 1ddd990687 ci: fix ./v check-md . 2021-05-11 11:19:13 +03:00