Build and deploy
What each change triggers
What tifa dev does after each kind of file change
tifa dev watches the app root and skips .git, .tifa, node_modules, and bin/, where the dev executable lives. Changes are handled in batches. A file joins a batch once it stays unchanged for 100 ms, so a build does not start in the middle of a save, and a batch starts once all its files have. A file that keeps changing, such as one a tool writes over and over, joins after one second anyway, and the files that are ready then go without waiting for the rest, so nothing is held back for much longer than a second.
| What changed | Steps that run | Open pages |
|---|---|---|
.ts, .tsx, .js, .css, .json outside content/, such as a component, or a page.tsx that exports only its component and ErrorBoundary |
bundle (the SSR bundle) | Update in place through Vite |
A .css file that a module of the SSR bundle imports, outside content/ and the public folder, edited while no error shows, when the SSR bundle imports every stylesheet for its side effect alone (no CSS modules, nothing imported with ?inline, ?url or ?raw) |
styles: Vite's dev server compiles the stylesheets the pages link, and a failure shows as a build error. The SSR bundle holds no CSS, so it stays as it is. | Update in place through Vite |
A module that exports more than components, such as a page.tsx or layout.tsx that exports head, or a root layout.tsx with documentHead |
bundle (the SSR bundle) | Reload, started by Vite |
A file in the app root that the last SSR bundle read, of any type, such as a Markdown or YAML file imported with ?raw: edited or removed |
bundle (the SSR bundle) | Through Vite, as for any front end change |
| A file added to the public folder or removed from it | bundle (the code is generated again first) | Through Vite, as for any front end change |
.env in the app root |
none: the app starts again and reads it | Reload |
.go, go.mod, go.sum |
static analysis, go build | Reload |
A file the Go code embeds with go:embed, of any kind, such as a Markdown post: edited |
go build (and the bundle too, for a .ts, .tsx, .js, .css or .json file) |
Reload |
| A file the Go code embeds, added or removed | static analysis, go build | Reload |
| As above, and the route manifest changed (routes, the result types of Load and Layout, the input and result types of handlers, hooks, etc.) | static analysis, code generation, bundle, go build | Reload |
A page.tsx, layout.tsx or layout_.tsx added or removed, a _locales/<language>.json added, removed or renamed (a draft too), or tifa.yaml changed |
all steps | Reload |
A Markdown file of a collection under content/, its body or its front matter, also one added or removed, or with a new slug or translationKey |
content: the scan of content/ in Go and the conversion of that entry |
Reload |
Another file under content/, of any kind, such as an image, a .json or a .css of a page bundle |
content: the entries in its folder, and the translations that fall back to that folder | Reload |
A folder added to content/ or removed from it, also an empty one |
content: the scan of content/, which reports a folder no collection declares |
Reload |
content.go or a schema type |
static analysis, go build (code generation and bundle when the types of the pages change), content of every entry | Reload |
vite.config.ts or a plugin file it imports |
bundle, then content of every entry, once Vite's dev server restarted. In an app without pages, which runs no dev server, any front end file, package.json included, converts every entry |
Reload |
- A front end change reaches open pages through Vite: React Fast Refresh swaps the edited components and keeps their state, and new CSS replaces the old. Vite reloads the page itself when a module cannot be swapped, such as one that exports more than components. A change to
vite.config.tsrestarts Vite's dev server, and one totsconfig.jsonreloads the page. Vite's dev server may keep importing the old target of a changedpathsentry untiltifa devrestarts. - At the same time
tifa devrebuilds the SSR bundle, without go build, and the running app loads it from.tifa/distin place of the old one. The app does not restart:OnStartdoes not run again, and what the app keeps in memory stays. When the newssr.jsand its source map are byte for byte the ones the app runs, as after an edit of a comment, the app keeps its VMs as well. A page request that arrives during a rebuild that makes a new SSR bundle waits for it, up to 30 seconds, so a reload shows the new server render. A request that arrives right after a save, while the files go quiet and before the rebuild starts, waits for it too: Vite reloads the page as soon as it sees the save, and that reload gets the new server render. An SSR bundle that builds while Vite's dev server restarts waits for the restart, and builds again on the new server if the restart made it fail. This holds from the start of the rebuild, also when it redoes a bundle that a failed rebuild left undone, or for a Go change, from the moment static analysis finds a new route manifest, before code generation. - The dev program calls
server.DevMainin place ofserver.Main. Only it answerstifa dev'sPOST /__tifa/dev/reload, and it loads the bundle with the same code that loads it at start. Only it stops whentifa devends, by reading the pipe thattifa devpasses to it with--lifeline-fd. The programtifa buildmakes callsserver.Mainand has no such path or flag. - Whether the route manifest changed is decided by the
.tifa/content generated after static analysis. If only function bodies changed, the generated content stays the same, and generation and bundling are skipped. - Every bundle and every go build checks the generated files in
.tifa/against the disk, and writes back one that something else changed or deleted. Files with the right content are not touched. - A file in the app root that the SSR bundle read, such as a text file imported with
?raw, is watched even thoughtifa devskips its type: the SSR bundle lists the files it read, andtifa devwatches those and no other files of the root. A file that a new bundle starts to read joins after that bundle. A file the bundle did not read, such as a Markdown file nothing imports, still builds nothing. - A file outside the app root that Vite's dev server loads, such as the source of another package in a workspace or a text file imported with
?raw, is watched by Vite rather thantifa dev. When it changes,tifa devrebuilds the SSR bundle too, whatever the kind of file, as it does for a front end file of the app, and the log names it by its path from the app root. Such a file can change while Vite's dev server restarts, when neither the old watcher nor the new one sees it. So each time restarts of the dev server end, whatever started them and whether they worked,tifa devrebuilds the SSR bundle once (restarts that overlap count as one), and the log saysVite's dev server restarted. The new watcher goes on watching the files outside the root that the old one watched. - Vite restarts its dev server without waiting for the new file watcher to read the app root, and a file the watcher has not reached has no starting point yet: an edit before that is never seen, so a module the dev server already served stays old until the file changes again. So after a restart the dev server answers requests once its watcher has read the files, which takes longer in a large app.
- A file that
go:embedtakes into the program is part of it, so a change builds it again, though the file is not Go.tifa devlearns which files these are from the static analysis, which asks the go command for the embedded files and patterns of every package in the module, and it watches them from then on, also a new file that a pattern such as//go:embed postsorposts/*.mdtakes. Folders named withoutall:leave out names that start with.or_, as the go command does, and so does a folder with its owngo.mod, which is another module. The analysis runs again for a file that appears or disappears, since it can change which files are embedded, and an edit only needs go build. A file that is both embedded and a front end file, such as a.jsonthe page imports, runs both steps. An embedded file in a folder thattifa devskips (see above) is not watched. Until the first analysis works, embedded files are not known. - Changing the content of an image, font or other file in the public folder triggers no rebuild. The next bundle copies only the files that changed, and removes the ones that went, so large public files cost nothing on a rebuild that left them alone. A file added to the public folder or removed from it runs the bundle step, which generates the code again, since the generated route code lists the public files (see Route tree). The log names the file as it does any change. A change of
build.publicintifa.yamlmoves the folder that is watched, with no restart. - Content does not need go build: the dev program reads
content.jsonand the bodies from.tifa/dist(see Content). The content step rescanscontent/in Go, converts the entries that changed in the Node process of Vite's dev server, and writes.tifa/dist/content/andcontent.json. Each conversion writes its bodies into a folder of its own under.tifa/dist/content/, so the bodies the app shows never change under it. The running app then loads the content again, runsValidateon every entry and takes the new data and bodies, and a page you load after that shows the new content. The app does not restart andOnStartdoes not run again. The first start converts every entry once. After a Go change in an app with collections the content step runs too, since the collections or their schema types may have changed, and converts every entry when they did. - Under
tifa devthe content holds drafts, withDrafttrue, and entries whose date is still to come, with theirDate, so you see a post in its lists and on its page while you write it. A page can mark them. - A front matter that does not fit the schema, a folder under
content/that no collection declares, or an error of a plugin shows the overlay with the message oftifa build, and the app keeps the content it had. An entry that failsValidateshows the overlay titledThe app did not load the content, and the app keeps the content it had too, with its old bodies. - Stylesheets go through Vite's dev server, so
@tailwindcss/vitecompiles Tailwind CSS the way it does in any Vite app. The SSR bundle holds no CSS. While it builds, the dev server compiles the stylesheets the pages link, so one that does not compile fails the bundle step, as it failstifa build. - The head of a page links the stylesheets that the server render imports, from Vite's dev server, so the page is styled before its scripts run, as a built page is. Vite updates these links when a stylesheet changes. A stylesheet that only
.clientmodules import arrives with their scripts. - The head of a page carries the Vite client and the React refresh runtime, and no other tag a Vite plugin adds with
transformIndexHtml(analytics, a manifest link, a favicon and the like).tifa buildhas noindex.htmland never runs that hook, so those tags would be in the page undertifa devand missing in production. Put such a tag in theheadexport of the rootlayout.tsx. For each onetifa devleaves out, it prints a warning once at start that names the tag. - An image or other file a module imports by URL gets the URL of Vite's dev server in the server render too, the same one the browser modules use, so hydration matches.
tifa buildgives it a hashed file under/assets/. build.targetonly applies totifa build. Vite's dev server sends modern JavaScript.