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

fix: ISR support for adapter-vercel #9063

Merged
merged 9 commits into from
Feb 17, 2023
Merged

fix: ISR support for adapter-vercel #9063

merged 9 commits into from
Feb 17, 2023

Conversation

Rich-Harris
Copy link
Member

We shipped incremental static regeneration on Vercel last week, but it was broken. Turns out there were a few extra hoops to jump through.

Brief explanation of the changes:

  • every route needs a group, so that if you invalidate /foo you simultaneously invalidate /foo/__data.json — this is assigned automatically
  • the pathname is passed to the prerender function as the __pathname query parameter. req.url is reconstructed by adapter-vercel before the request is handed off to SvelteKit
  • so that we can know if /foo or /foo/__data.json is being requested, while still allowing /foo and /foo/__data.json to be invalidate simultaneously, we need to create two Vercel routes for each SvelteKit route with isr. To save space, these are symlinks rather than duplicates

Please don't delete this checklist! Before submitting the PR, please make sure you do the following:

  • It's really useful if your PR references an issue where it is discussed ahead of time. In many cases, features are absent for a reason. For large changes, please create an RFC: https://github.com/sveltejs/rfcs
  • This message body should clearly illustrate what problems it solves.
  • Ideally, include a test that fails without this PR but passes with it.

Tests

  • Run the tests with pnpm test and lint the project with pnpm lint and pnpm check

Changesets

  • If your PR makes a change that should be noted in one or more packages' changelogs, generate a changeset by running pnpm changeset and following the prompts. Changesets that add features should be minor and those that fix bugs should be patch. Please prefix changeset messages with feat:, fix:, or chore:.

@Rich-Harris Rich-Harris changed the title Vercel isr fix: ISR support for adapter-vercel Feb 16, 2023
Copy link
Member

@dummdidumm dummdidumm left a comment

Choose a reason for hiding this comment

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

In line 223 (previously 215) there's a special handling for the common case of a single group. I think the if-condition needs to be adjusted here to also check that there's no ISR config. Because if the functions isn't set there, ISR will not picked up (functions is just empty). This could happen if you set IRS at the adapter level.

packages/adapter-vercel/index.js Outdated Show resolved Hide resolved
packages/adapter-vercel/index.js Outdated Show resolved Hide resolved
const name = functions.get(pattern);
if (name) {
static_config.routes.push({ src, dest: `/${name}` });
functions.delete(pattern);
const isr = isr_config.get(route);
Copy link
Member

Choose a reason for hiding this comment

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

If you don't have any route config, we'll never get into here because functions is empty (because of line 216)

Copy link
Member Author

Choose a reason for hiding this comment

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

nice catch. fixed

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.

3 participants