This package is experimental. It may not be suitable for production use at this time, as it is subject to bugs and breaking changes.(invalid icon)
npm install thunderous-csr
import { View } from 'thunderous-csr';
View.define('t-view'); // You can use any tag name
<!-- On every page that should have SPA-like navigation -->
<t-view id="main">
<!-- Your page content -->
</t-view>
<t-view>Thunderous CSR only handles the client side. It expects HTML to be served separately.(invalid icon)
<t-view>
<!-- page1.html -->
<body>
<t-view id="content">
<h1>Page 1</h1>
<a href="/page2">Go to Page 2</a>
</t-view>
</body>
<!-- page2.html -->
<body>
<t-view id="content">
<h1>Page 2</h1>
<a href="/page1">Back to Page 1</a>
</t-view>
</body>
<t-view id="content"> id
<body>
<t-view id="sidebar">
<!-- Sidebar content can differ per-page -->
<nav>...</nav>
</t-view>
<main>
<t-view id="main">
<!-- Main content swaps independently -->
</t-view>
</main>
<script type="module" src="/main.js"></script>
</body>
import { View } from 'thunderous-csr';
// Register with your preferred tag name
View.define('t-view'); // Standard
View.define('app-view'); // Custom name
View.define('page-content'); // Your choice
// Call this EXACTLY ONCE in your application
import { viewRegistry } from 'thunderous-csr';
// Look up the registered tag name dynamically
const tagName = viewRegistry.getTagName(View); // Returns 't-view'
ViewElement <t-view> status 'pending' | 'ready' | 'error' finished Promise<void>
const view = document.getElementById('main');
console.log(view.status); // 'pending', 'ready', or 'error'
// Wait for navigation to finish
await view.finished;
console.log('Navigation complete!');
.pending .ready .error
t-view.pending {
opacity: 0.7;
}
t-view.ready {
opacity: 1;
transition: opacity 0.3s ease;
}
t-view.error {
border: 2px solid red;
}
loading-overlay
<t-view id="main">
<div slot="loading-overlay" class="my-spinner">
<img src="/spinner.svg" alt="Loading...">
</div>
<!-- Main content here -->
</t-view>
@view-transition view-transition-name view-transition-class :active-view-transition ::view-transition ::view-transition-group ::view-transition-image-pair ::view-transition-old ::view-transition-new navigation activation canGoBack canGoForward currentEntry entries() back() forward() navigate() traverseTo() updateCurrentEntry() NavigationEventBrowser support for these features may be limited. Please check the support tables on the linked MDN pages before using them in production.(invalid icon)
<!-- page1.html -->
<t-view id="content">...</t-view>
<!-- page2.html -->
<t-view id="main">...</t-view>
<!-- Different ID! -->
<!-- BAD: Confusing behavior, will cause errors -->
<main>
<t-view id="main">
<p>Main content</p>
<aside>
<t-view id="aside">
<p>Side content</p>
</t-view>
</aside>
</t-view>
</main>
<main>
<t-view id="main">
<p>Main content</p>
</t-view>
<aside>
<t-view id="aside">
<p>Side content</p>
</t-view>
</aside>
</main>
<t-view>