Releases: jaredpalmer/after.js
v3.2.0
Static Site Generation (SSG)
After.js has first class support for SSG and allows you to create super fast static web apps and serve them over CDN. (needs razzle 4)
renderStatic
will return the data from getInitialProps
and this data will get saved by razzle into a file called page-data.json
. After.js won't call getInitialProps
at runtime, instead it will read the page-data.json
and pass it as a prop to your component.
from ./src/static_export.js
you should export render and routes function.
async render(req, res)
should render your app into html and at the end it should return html and data.async routes()
should return path for pages you want to statically generate.
// ./src/static_export.js
import { renderStatic } from '@jaredpalmer/after';
import appRoutes from './routes';
const assets = require(process.env.RAZZLE_ASSETS_MANIFEST);
const chunks = require(process.env.RAZZLE_CHUNKS_MANIFEST);
export const render = async (req, res) => {
const { html, data } = await renderStatic({
req,
res,
routes: appRoutes,
assets,
chunks,
});
res.json({ html, data });
};
export const routes = async () => {
return ['/', '/about'];
};
after setting up this file you can build your app and run export script to generate your static site:
yarn build
yarn export
Minor Changes
- Examples: add with-prerender example: 854a647
- Chore(examples): update with-prerender README.md: 69fb6e2
- Fix(examples): Update README.md: 5876e7f
- Refactor(after): make <After /> more readable: 2c79809
- Feat(after): add loadStaticProps: d78b967
- Feat(after): add ssg flag to AfterClientData type: 668fee6
- Feat(after): Update render.tsx: 0592897
- Feat(after): call loadStaticProps in ssg mode: 226e4b8
- Feat(after): change render to renderApp: b99189f
- Feat(after)L add renderStatic method: 04b9fe4
- Feat(after): add render method: 23c2e5e
- Feat(after): re-export renderApp and renderStatic: 3f43f26
- Feat(after): export renderApp and renderStatic: 61810c5
- Examples: Update with-prerender example: 2611083
- Feat(after): Update render: 6e512d6
- Feat(after): Update Tests: eac8e48
- Feat(after): change loadInitialProps args order: 4a85396
- Feat(after): read data from page-data file prefetch(): d3bae33
- Examples(prerender): Use paths.js: ca3e20c
- Examples(prerender): Update server.js: 97b6ab9
- Examples(pre-render): Update About.js: 2570cea
- Feat(after): fix index path page-data.json: b0648f9
- Fix-typo: f16c68a
- Feat: load manifest plugin for examples: 2ea52a8
- Feat: move tests outside src directory: 47b24ba
- Refactor: prettier update code style: a745a96
- Refactor: remove unsued files: 87410ef
- Feat: add github workflows: d82e52f
- Feat: add npmignore for basic-example folder: 2ef20f8
- Chore: update configs: d77eaa7
- Chore: UPDATE yarn.lcok file: b9a9cf5
- Refactor: move workflows into root directory: 3dc549c
- Feat: update size limit: 16efe83
- Feat: use tsdx for after.js package development: 0a88526
- Merge pull request #471 from wokayme/fix-typo: 099c044
- Merge branch 'master' into feature/pre-render: 12cbd61
- Refactor: remove unused files: 60e2466
- Refactor: remove yarn lock file for examples: 46e9f98
- Feat(examples): UPDATE razzle deps to v4: 5ad4910
- Feat: add manifest plugin to examples: b53398c
- Chore: add cache folder to gitignore: 9b0d412
- Feat: update depdencies of basic example: 744feed
- Merge pull request #507 from jaredpalmer/feature/support-razzle-4: 84db62b
- Merge branch 'master' into feature/pre-render: f000f7a
- Feat: UPDATE static-export example: c07e9fa
- Feat: UPDATE README.md: b3c7778
- Feat: UPDATE README.me: 582a581
- Feat: UPDATE REAMDME.md: a9a0a4f
- Merge pull request #370 from jaredpalmer/feature/pre-render: 556dd2b
v3.1.3
Fix Scroll To Top and getInitialProps statusCode and redirectTo bug
Scroll To Top before calling getInitialProps in instant mode
in instant mode, getInitialProps gets called and at the same time the page scrolls to the top
in blocked mode, getInitialProps gets called and then when the promise that returned from it get resolved we scroll to top
Patches
- fix(after): fix scroll to top in instantMode: c1fa60b
Transition Behavior
isLoading
prop now gets injected to page components
isLoading
prop shows that if getInitialProps
is in pending state
or not
function HomePage({ isLoading, error, data }) {
if (isLoading) {
return <Spinner />
}
if (error) {
return <span>something went wrong</span>
}
return <MyComponent data={data} />
}
HomePage.getInitialProps = () => {
try {
const { data } = await fetchHomePage();
return { data }
} catch (error) {
return { error }
}
}
New transitionBehavior prop on <After />
// transitionBehavior: instant | blocked
<After transitionBehavior="instant" /> // default is `blocked`
blocked behavior (default):
navigation event occurs
-> wait until getInitailProps get finished
-> render the next page with injected props (I mean results of the getInitailProps)
instant behavior:
navigation event occurs
-> call getInitailProps
-> render the next page
-> re-render component when getInitailProps is finished with injected props
Minor Changes
- Feat(after): add TransitionBehavior type: 27d0c64
- Feat(after): add logic for instant transition: b335f4c
- Feat(after): pass transitionBehavior to render render page: 6b37ea9
- Feat(after): add isInstantTransition utility func: 30d906f
- Feat(after): clean up render method: 5a64ed4
- Feat(after): add isLoading state: 95dea98
- Merge pull request #348 from jaredpalmer/feature/transition-behavior: 639d344
Don't scroll when user clicked on anchor links
Transition Behavior
new transitionBehavior prop on <After />
transitionBehavior: instant | blocked
the default for value for transitionBehavior
prop is blocked
(we can also change the default to instant
but it's going to be a breaking change)
blocked behavior (default):
navigation event occurs
-> wait until getInitailProps get finished
-> render the next page with injected props (I mean results of the getInitailProps)
instant behavior:
navigation event occurs
-> call getInitailProps
-> render the next page
-> re-render component when getInitailProps is finished with injected props
Don't load source maps
v3.0.1
Load Assets Faster!
We Skipped version 2, there was a problem with our deployments to npm so a canary release tagged as a stable release and ...
Load Assets Faster!
Upgrading to version 3 should not take more than 10 minutes.
In v1, with asyncComponent
you split part of your application into a new chunk, and on BROWSER when you need that part of your code it gets downloaded automatically. when page rendered on the server there was no way to understand which chunks needed for the current request so After.js only sends client.js
and styles.css
file, then on BROWSER with ensureReady
method it tries to fetch chunks (split CSS and JS files) needed for the current request. and it's slow!
WHY?
-
browser must download
client.js
, then parse it and at the end, it executes the code. when code gets executedensureReady
method gets called,ensureReady
finds and download chunks needed to render the current page and when all files get downloaded it start to re-hydrate. -
browser will render the page without CSS styles (because we split them and it will get them when
ensureReady
called), this makes the site look ugly for 2,3 seconds (bad UX). -
have you ever think about why CSS is render blocking?
if browser finds a<link rel="stylesheet">
tag, it would stop rendering page and waits until CSS file be downloaded and parsed completely (this mechanism is necessary to have fast page renders), if CSS files attach to dom after page gets rendered, the browser must repaint the whole page. (painting is too much job for browser and it's slow)
in After.js 2 this problem is solved and it sends all JS and CSS files needed for current requests in the initial server response.
Major Changes
Minor Changes
- Merge branch 'master' of https://github.com/jaredpalmer/after.js: 9ce92f3
- Feat(create-after-app): update default template: ae581ee
- Chore: update UPGRADING.md: 65bb605