Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(lambda-at-edge, nextjs-component, s3-static-assets): support ver… #803

Merged
merged 6 commits into from Nov 17, 2020

Conversation

dphang
Copy link
Collaborator

@dphang dphang commented Nov 16, 2020

…sioned static pages (currently only next data is versioned) for proper fallback SSG generation, never cache fallback pages

  • This will create versioned static pages directory for assets e.g static-pages/build1, static-pages/build2. It also copies the BUILD_ID file to assets/BUILD_ID or assets/basepath/BUILD_ID to represent the current latest version that was just uploaded to S3.
  • When the BUILD_ID file is present in S3, it uses it and the AWS S3 SDK to clear all previous build versions of _next/data/<build_id> and static-pages/<build_id> except the version in BUILD_ID. It doesn't remove existing pages in the root static-pages directory, so it won't be destructive when transitioning from old to new Lambda versions. This happens before the S3 upload of the new build version. Then once the new S3 assets are uploaded, only the new + previous build versions are present. This is to help us save on S3 storage costs and ensure Lambda doesn't break on deployment transitions.
  • This (along with cache control fixes) is needed to fix fallback SSG generation, as currently fallback pages are not versioned and put into static-pages/pages.html. This never gets deleted, so subsequent deployments may be getting an old generated page for an SSG fallback. By using versioned pages instead, we can ensure that it gets updated (and old ones get cleared after deployments).
  • Versioning pages could also fix a general issue (not fallback specific) where when transitioning between Lambda deployments, a newer version's page is served (via S3) by an older Lambda, due to S3 uploading finishing before the newer Lambda could propagate, which could possibly cause issues (but probably rare?)
  • Fallback pages are never cached (Cache-Control in both rendering + S3 upload is set to no-store) and now can also use the versioned pages properly.

Tests

Updated unit and e2e tests. Added tests for new S3 removal method for both with and without basePath.

…sioned static pages/next data for proper fallback SSG generation, never cache fallback pages
@codecov
Copy link

codecov bot commented Nov 16, 2020

Codecov Report

Merging #803 (1b585bf) into master (8d384cf) will increase coverage by 0.30%.
The diff coverage is 93.22%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master     #803      +/-   ##
==========================================
+ Coverage   80.23%   80.54%   +0.30%     
==========================================
  Files          57       57              
  Lines        1862     1912      +50     
  Branches      410      422      +12     
==========================================
+ Hits         1494     1540      +46     
- Misses        310      313       +3     
- Partials       58       59       +1     
Impacted Files Coverage Δ
...ackages/libs/lambda-at-edge/src/default-handler.ts 94.02% <66.66%> (-0.76%) ⬇️
packages/libs/s3-static-assets/src/lib/s3.ts 95.23% <96.66%> (+3.57%) ⬆️
packages/libs/lambda-at-edge/src/build.ts 91.56% <100.00%> (+0.06%) ⬆️
packages/libs/s3-static-assets/src/index.ts 100.00% <100.00%> (ø)
...ackages/libs/s3-static-assets/src/lib/constants.ts 100.00% <100.00%> (ø)
...rless-components/nextjs-component/src/component.ts 90.60% <100.00%> (+0.06%) ⬆️
...ibs/s3-static-assets/src/lib/readDirectoryFiles.ts 88.88% <0.00%> (-11.12%) ⬇️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 8d384cf...1b585bf. Read the comment docs.

@dphang dphang marked this pull request as ready for review November 17, 2020 05:09
Copy link
Contributor

@danielcondemarin danielcondemarin left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM 👍

@dphang dphang merged commit 015065d into master Nov 17, 2020
@delete-merged-branch delete-merged-branch bot deleted the dphang/versioned-pages branch November 17, 2020 20:24
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants