
Security News
Deno 2.2 Improves Dependency Management and Expands Node.js Compatibility
Deno 2.2 enhances Node.js compatibility, improves dependency management, adds OpenTelemetry support, and expands linting and task automation for developers.
@enhance/ssr
Advanced tools
Server sider render for custom elements.
Enhance enables a web component workflow that embraces templates and slots.
npm i @enhance/ssr
const html = require('@enhance/ssr')()
console.log(html`<hello-world greeting="Well hi!"></hello-world>`)
By default enhance looks for templates in your projects /src/views/templates
directory.
Configure where it should look by passing a templates
option in a configuration object.
const html = require('@enhance/ssr')({ templates: '/components' })
console.log(html`<hello-world greeting="Well hi!"></hello-world>`)
⚠️
templates
supports any pathrequire
can.
An example template for use in Server Side Rendering
// Template
module.exports = function HelloWorldTemplate(state={}, html) {
const { greeting='Hello World' } = state
return html`
<style>
h1 {
color: red;
}
</style>
<h1>${greeting}</h1>
<script type=module>
class HelloWorld extends HTMLElement {
constructor () {
super()
const template = document.getElementById('hello-world-template')
this.attachShadow({ mode: 'open' })
.appendChild(template.content.cloneNode(true))
}
connectedCallback () {
console.log('Why hello there 👋')
}
}
customElements.define('hello-world', HelloWorld)
</script>
`
}
The template added to the server rendered HTML page
// Output
<template id="hello-world-template">
<style>
h1 {
color: red;
}
</style>
<h1>Hello World</h1>
<script type=module>
class HelloWorld extends HTMLElement {
constructor () {
super()
const template = document.getElementById('hello-world-template')
this.attachShadow({ mode: 'open' })
.appendChild(template.content.cloneNode(true))
}
connectedCallback () {
console.log('Why hello there 👋')
}
}
customElements.define('hello-world', HelloWorld)
</script>
</template>
Supply initital state to enhance and it will be passed as the third argument to your template functions.
// Template
module.exports = function MyStoreData(state, html, store) {
const appIndex = state['app-index']
const userIndex = state['user-index']
const { id='', name='' } = store?.apps?.[appIndex]?.users?.[userIndex] || {}
return `
<div>
<h1>${name}</h1>
<h1>${id}</h1>
</div>
`
}
Attribute state can be used to pass default state to the backing Web Component. Store is used to pass previously stored data, in an easy to access way, to all components in the tree.
⚠️ Enhance renders one line of JavaScript into the page for extracting script tags from your templates.
P.S. Enhance works really well with Architect.
FAQs
Server-side rendering for custom elements with template and slots support
The npm package @enhance/ssr receives a total of 181 weekly downloads. As such, @enhance/ssr popularity was classified as not popular.
We found that @enhance/ssr demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 0 open source maintainers collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
Deno 2.2 enhances Node.js compatibility, improves dependency management, adds OpenTelemetry support, and expands linting and task automation for developers.
Security News
React's CRA deprecation announcement sparked community criticism over framework recommendations, leading to quick updates acknowledging build tools like Vite as valid alternatives.
Security News
Ransomware payment rates hit an all-time low in 2024 as law enforcement crackdowns, stronger defenses, and shifting policies make attacks riskier and less profitable.