Reference › Project
clarusjs 0.8.1
All releases · [email protected] on npm
Patch Changes
- Production builds leave out the development-only
@forduplicate-key warning (it is behindimport.meta.env?.DEV). The package declaressideEffects: only the loader, router, fragment navigation andclarusjs/navigationrun code when loaded, so bundlers drop unused runtime modules. #198 clarusjs checkuses a JavaScript project'sjsconfig.jsonlike atsconfig.json. #209- A client route whose first render fails shows the site's 404 or 500 page (
src/pages/404.tscl,500.tscl) at the same URL, with its islands and stylesheets (the shell links them). Without one, it shows "Could not load page." (also for a missing page, which said "Page not found." before). #204 - Error pages. When a page rendered on request fails (its
load()throws or it can't render), the answer is the site'ssrc/pages/500.tsclwith status 500 (it gets astatusinput), or plain text without one; the error only goes to the server log. Builds also write500.html(left out of the sitemap). In development, the dev server shows the error itself with its stack instead. #201 - Navigation fixes from review: - a navigation cancelled before it starts (a
beforeNavigatehook) no longer leavesdata-cl-navigatingset or sends a later history change to the cancelled URL; - a failure before the URL changed is reported with the error itself, and the normal page load starts after that; -afterSwapandafterNavigaterun once the new page's islands that attach right away are attached; -onNavigateErrorgets the page it was going to; - a hook whose island was released by an earlier hook is skipped; - the 500 page keepsstatuswhen it has its ownload(); - a redirect whose file would replace a generated page or data file, or land outside the site, fails the build; - the browser runtime typechecks from source without anImportMeta.envdeclaration. #206 - Aborting a navigation.
abort()inclarusjs/navigationstops the navigation in progress, like the browser's stop button. Push and replace navigations now hold the URL while the next page loads where the browser supports it (precommit handlers): the address bar changes once the page is ready to swap in, so an abort leaves page and URL as they were (elsewhere the URL changes at once, as before). Fragment and__data.jsonrequests get the navigation's abort signal, so a stopped or superseded navigation stops downloading. A page's ownreplaceStatewhile a held navigation loads no longer loses the clicked page. #200 - Navigation hooks in
clarusjs/navigation:beforeNavigate(can cancel),afterNavigateandonNavigateError, released with the island that registered them. A failed fragment swap or client render is now reported asnavigateerrorbefore the page loads normally. #188 - New entry
clarusjs/navigationfor islands:navigate(to, { replace, state })andback()move between pages through the page's navigator (fragments or the client router, as a link click would), andcurrentUrlis the current URL as a store (let here = shared(currentUrl);nullon the server). Without the Navigation API,navigate()is a normal page load. Ships only with islands that import it. #187 - Transitions: every page change the router or fragment navigation takes over goes through
loadingthenswapping, shown on<html data-cl-navigating>for CSS. Inclarusjs/navigation: thenavigatingstore, and the in-between hooksbeforeSwap(the next page is loaded, this one still shown) andafterSwap(the new page is in). Hooks may return a promise, which the page change waits for;t.signalaborts when a newer navigation takes over. #190 - Path aliases.
~/issrc/, built in. Aliases fromtsconfig.json/jsconfig.jsonpathsand Vite'sresolve.aliaswork in@import(components, data, stylesheets), island scripts and.load.tsfiles, resolved the same way in dev, build, prerender andclarusjs check(which no longer drops the project'spaths). An import that no file, package or alias matches is an error at its@import(file.tscl:line:col). #210 - Redirects. A server page's
load()can return aResponse, such asredirect('/login')fromclarusjs/server(302 by default; 301, 303, 307 or 308). Fragment navigation and the client router follow it by loading the page normally, so the address bar shows where it landed. The plugin'sredirects: { '/old': '/new' }writes a forwarding page at each old path and_redirectslines (a real 301 on Netlify and Cloudflare Pages), and the dev server answers 301; old paths pass the link check, and a redirect from a path that is a page is a build error. #195 - The client router leaves the page's own
history.pushStateandreplaceStatealone: they no longer re-render the route (which lost focus and state and fetched__data.jsonagain). Back and forward still render, and areplaceStatewhile the next page loads still shows that page. #177 - The client router and fragment navigation decide which navigations to take over in one shared place. Behaviour is unchanged; each script carries its own copy, so pages load no extra file. #186
- Typed routes:
href(route, params)fromclarusjs/navigationbuilds a page's URL from its route ('/releases/[version]'), with params encoded and the site's base.clarusjs checkwrites.clarusjs/routes.d.ts(every page undersrc/pages, Markdown pages too), so a route that doesn't exist or a missing param is a type error. #208 - View transitions:
viewTransitions()fromclarusjs/navigationruns page changes (fragment swaps and client routes) insidedocument.startViewTransitionwhere the browser has it; elsewhere they stay instant.beforeSwapruns before the browser's snapshot,afterSwaponce the new page is in. #207