Security News
Research
Data Theft Repackaged: A Case Study in Malicious Wrapper Packages on npm
The Socket Research Team breaks down a malicious wrapper package that uses obfuscation to harvest credentials and exfiltrate sensitive data.
react-snapshot
Advanced tools
A zero-configuration static pre-renderer for React apps. Starting by targetting Create React App (because it's great)
A zero-configuration static pre-renderer for React apps. Starting by targetting Create React App (because it's great)
Server-side rendering is a big feature of React, but for most apps it can be more trouble than its worth. Personally, I think the sweet spot is taking static site snapshots of all your publicly-accessible pages & leaving anything requiring authentication as a normal, JS-driven Single Page App.
This is a project to do that. Automatically, without any configuration, just smart defaults. Retrospective progressive enhancement.
The snapshots still have the normal JS bundle included, so once that downloads the site will function exactly as before (i.e. instantaneous page transitions), but you serve real, functional HTML & CSS as soon as possible. It's good for SEO (yes Google crawls SPAs now but they still reward perf and this perfs like a banshee), it's good if your JS is broken or something render-blocking has a network fail, it's good for accessibility, it's good for Slackbot or Facebook to read your opengraph tags, it's just good.
npm i -D react-snapshot
"scripts"
from- "build": "react-scripts build"
+ "build": "react-scripts build && react-snapshot"
react-dom
:- import ReactDOM from 'react-dom';
+ import { render } from 'react-snapshot';
- ReactDOM.render(
+ render(
<App/>,
document.getElementById('root')
);
This calls ReactDOM.render
in development and ReactDOMServer.renderToString
when prerendering. If I can make this invisible I will but I can't think how at the moment.
Check out react-snapshot-demo.surge.sh for a live version or geelen/create-react-app-snapshot for how it was built, starting from create-react-app's awesome baseline. No ejecting necessary, either.
It's pretty simple in principle:
There's a few more steps to it, but not much.
build/index.html
to build/200.html
at the beginning, because it's a nice convention. Hosts like surge.sh understand this, serving 200.html
if no snapshot exists for a URL. If you use a different host I'm sure you can make it do the same.pushstate-server
is used to serve the build
directory & serving 200.html
by defaultThis is a hacky experiment at the moment. I would really like to see how far we can take this approach so things "just work" without ever adding config. Off the top of my head:
pushstate-server
serves 200.html
even if a HTML snapshot is present. So once you've run react-snapshot
, you have to switch to http-server
or superstatic
to test if it worked. Or you could just push to surge.sh each time, which isn't too bad./
and crawling sufficient? Might there be unreachable sections of your site?robots.txt
file?200.html
pushstate fallback? What if you want to remove the bundle (effectively making this a static site generator)?build
directory to something like snapshot
or dist
instead of modifying it in-place?This should work for simple cases. For less simple cases, go with:
MIT
FAQs
A zero-configuration static pre-renderer for React apps. Starting by targeting Create React App (because it's great)
The npm package react-snapshot receives a total of 827 weekly downloads. As such, react-snapshot popularity was classified as not popular.
We found that react-snapshot 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
Research
The Socket Research Team breaks down a malicious wrapper package that uses obfuscation to harvest credentials and exfiltrate sensitive data.
Research
Security News
Attackers used a malicious npm package typosquatting a popular ESLint plugin to steal sensitive data, execute commands, and exploit developer systems.
Security News
The Ultralytics' PyPI Package was compromised four times in one weekend through GitHub Actions cache poisoning and failure to rotate previously compromised API tokens.