
Security News
Socket Releases Free Certified Patches for Critical vm2 Sandbox Escape
A critical vm2 sandbox escape can allow untrusted JavaScript to break isolation and execute commands on the host Node.js process.
ts-liveview
Advanced tools
LiveView enables rich, real-time user experiences with server-rendered HTML
LiveView enables rich, real-time user experiences with server-rendered HTML.
Just like Phoenix LiveView but in Typescript!
| Tools | Runtime Code Size (minified) |
|---|---|
| TS LiveView v0 + morphdom | 8K |
| (Phoenix) LiveView.js + morphdom | 29K |
| TS LiveView v1 + morphdom + primus.js | 46K |
| Vue 2.5.20 | 88K |
| React 16.6.3 + React DOM | 112K |
| Ember 3.0.0.beta.2 | 468K |
| React + Ionic * | 2.1M |
| Stencil + Ionic * | 3.0M |
| Angular + Ionic * | 4.2M |
*: all Ionic build excluded the svg, assets, *.map and PWA json files
Not only is LiveView + morphdom much lighter than the JS frameworks, the frameworks are just the baseline. You still need to ship application-specific JS and often add supporting JS libraries such as react-router, redux and friends to get feature parity. Those can easily boom the code size for runtime to be over 10MB, causing the latency of the first meaningful paint to be over 25 seconds on mobile device.
import { c, h, Session, startServer } from '../src'
function render(state: number) {
return c(
'#clock',
h`<div id="clock">${new Date(state).toLocaleString()}</div>`,
)
}
function createSession(session: Session): Session | void {
let state = Date.now()
function update() {
const view = render(state)
session.sendComponent(view)
}
const timer = setInterval(() => {
state = Date.now()
update()
}, 1000)
session.onClose(() => clearInterval(timer))
return session
}
startServer({
port: 3000,
heads: [
// default path for websocket lib
`<script src="/primus/primus.js"></script>`,
],
createSession,
initialRender: (req, res) => {
return render(Date.now())
},
})
import S from 's-js'
import { c, genPrimusScript, h, Request, Response, Session, startServer, } from '../src'
function initialView(req: Request, res: Response) {
return c('#app', h`<div id="app" class="init">
<p>
Now is: ${new Date().toLocaleString()}
</p>
<label>Name:</label>
<input onchange="send('name', event.target.value)">
<br>
<p>
Hello, Guest
</p>
</div>`)
}
// this callback will be called from a S.root context
// the context will be cleanup automatically when the client connection is closed
function createSession(session: Session): Session | void {
const clock = S.data(Date.now())
const timer = setInterval(() => clock(Date.now()), 1000)
S.cleanup(() => clearInterval(timer))
setInterval(() => clock(Date.now()), 1000)
function renderClock() {
return c(
'#clock',
h`<p id="clock">Now is: ${new Date(clock()).toLocaleString()}</p>`,
)
}
const name = S.data('')
function renderName() {
return c(
'#name',
h`<div id="name">
<label>Name: </label>
<input onchange="send('name', event.target.value)">
<p>
Hello, ${name() || 'Guest'}
</p>
</div>`,
)
}
function renderRoot() {
return S.sample(() =>
c(
'#app',
h`<div id="app" class="live">
${renderClock()}
${renderName()}
</div>`,
),
)
}
session.sendComponent(renderRoot())
session.live(renderClock, { skipInitialSend: true })
session.live(renderName, { skipInitialSend: true })
session.onMessage(message => {
const [k, v] = message
if (k !== 'name') {
console.warn('unknown client message:', message)
return
}
name(v)
})
return session
}
startServer({
port: 3000,
heads: [genPrimusScript()],
createSession,
initialRender: (req, res) => {
return initialView(req, res)
},
})
*: Solved by Primus
**: maybe use JSX/TSX?
If so, will be costly to detect changes.
Currently requires the developer to explicitly escape it, with the help of ts-liveivew/helpers/server#s()
BSD-2-Clause LICENSE (Free Open Source Software)
FAQs
LiveView enables rich, real-time user experiences with server-rendered HTML
The npm package ts-liveview receives a total of 39 weekly downloads. As such, ts-liveview popularity was classified as not popular.
We found that ts-liveview demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer 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
A critical vm2 sandbox escape can allow untrusted JavaScript to break isolation and execute commands on the host Node.js process.

Research
Five malicious NuGet packages impersonate Chinese .NET libraries to deploy a stealer targeting browser credentials, crypto wallets, SSH keys, and local files.

Security News
pnpm 11 turns on a 1-day Minimum Release Age and blocks exotic subdeps by default, adding safeguards against fast-moving supply chain attacks.