Skip to content

Releases: jaredpalmer/after.js

v3.2.0

01 Nov 22:06
Compare
Choose a tag to compare

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

19 Dec 17:13
Compare
Choose a tag to compare

Patches

  • Fix: update Document.js: a86c50c
  • Fix: update README.md: 4943651
  • Fix: document title not changing: b7ef7e1

Fix Scroll To Top and getInitialProps statusCode and redirectTo bug

02 Jul 21:04
Compare
Choose a tag to compare

Patches

  • Fixing comparison of pathname change: b02eb93
  • Fix(after): make redirect and 404 page work: f5585f0

Scroll To Top before calling getInitialProps in instant mode

29 Jun 12:18
Compare
Choose a tag to compare

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

28 Jun 23:51
Compare
Choose a tag to compare

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)

blocked

instant behavior:
navigation event occurs -> call getInitailProps -> render the next page -> re-render component when getInitailProps is finished with injected props

instant

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

28 Jun 23:40
Compare
Choose a tag to compare

Patches

  • Fix Anchor Link Scrolling to Top on Click: a0483f2
  • Merge pull request #360 from chansen424/fix-anchor-links-scrolling: 2d85c92

Transition Behavior

24 May 23:41
Compare
Choose a tag to compare
Transition Behavior Pre-release
Pre-release

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)

blocked

instant behavior:
navigation event occurs -> call getInitailProps -> render the next page -> re-render component when getInitailProps is finished with injected props

instant

Don't load source maps

29 Apr 17:10
Compare
Choose a tag to compare

Patches

  • Fix(after): add isJS utility: dd828e8
  • Fix(after): filter in JS files: 9cf025f
  • Fix(after): source maps: 666d1b4

v3.0.1

26 Apr 12:00
Compare
Choose a tag to compare

Patches

Fix(after): don't pass match object from props to loadInitialProps

Load Assets Faster!

25 Apr 20:46
Compare
Choose a tag to compare

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?

  1. browser must download client.js, then parse it and at the end, it executes the code. when code gets executed ensureReady 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.

  2. 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).

  3. 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.

READ MORE

Major Changes

  • Chore: update examples for new version: 0339d4f
  • V3: #323

Minor Changes

Patches