Skip to content

Improve existing hooks. - #10

Merged
koculu merged 1 commit into
mainfrom
improve-hooks
Oct 4, 2026
Merged

koculu merged 1 commit into
mainfrom
improve-hooks

Conversation

@koculu

@koculu koculu commented Oct 4, 2026

Copy link
Copy Markdown
Member

Summary

Page hooks now run on every page render, including dev-server re-renders. The package also exports the types hook and template authors need, and the ts-ssg README is corrected to match the code.

Page hooks run on every render

onPageStart, onPageRendered and onPageWritten used to fire only in full builds. Pages re-rendered in serve went through buildPage, which skipped them, so a hook that post-processed HTML worked in build and silently stopped working in serve after the first edit.

  • Full builds, eager renders of an edited page, and on-request renders after a shared change all go through one writePageWithHooks method in content-state.ts, so build and serve produce the same output.
  • With writeErrorPages (dev), a throwing hook during a re-render writes an error page, as it already did in full builds.
  • buildPage had no other callers and is removed.
  • onConfigResolved, onContentDiscovered, onNavigationBuilt, onStylesWritten and onBuildComplete still run once per full build, deliberately. For example, onContentDiscovered can do expensive work, such as the studio writing its preview files.

Exported types

@purestack/ts-ssg now exports:

  • Build and hooks: BuildOptions, BuildCountSummary, BuildContext, PageRenderResult, ResolvedContentFile, WriteStylesResult
  • Templates: PageTemplate, PageTemplateInput, PageTemplateMap, PageInfo, PageFrontmatter
  • Config and components: SiteConfig, SiteConfigInput, TsSsgContext

Previously a hook's context or a template's input couldn't be typed without importing internal paths.

README corrections

  • Quick starts: both examples passed site config at the top level and didn't compile; they now use siteConfig and build.siteConfig.
  • Templates: the example imported a type that wasn't exported; it now compiles and documents the template input.
  • Components: replaces a stale 16-item list with the component reference, explains options.components, and corrects the claim that components never run in the browser (PageScript, RegorApp).
  • Theming: names the real API, themeSkins and registerSkin from @purestack/ts-style; builtInSkins doesn't exist.
  • Markdown: documents the real siteConfig.mdx options in place of a nonexistent BuildInput.mdx.
  • Build hooks: when each hook runs, that page.html changes in onPageRendered are written, that hooks need the programmatic API, and an example.
  • API surface: lists exactly what the package exports.

Every README code example was type-checked against the real exports.

Testing

  • New incremental tests cover:
    • page hooks firing in the full build, for an edited page, and for a page rendered on request after a header edit;
    • page.html changes reaching disk;
    • a failing hook producing an error page during a re-render.
  • The ts-ssg suite passes, and Biome and TypeScript 7 are clean.

@koculu
koculu merged commit 2e4fa11 into main Oct 4, 2026
2 checks passed
@koculu
koculu deleted the improve-hooks branch October 4, 2026 02:37
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant