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

Allow dynamic route segments in @astrojs/vercel isr.exclude array #10492

Closed
1 task done
tk04 opened this issue Mar 19, 2024 · 5 comments
Closed
1 task done

Allow dynamic route segments in @astrojs/vercel isr.exclude array #10492

tk04 opened this issue Mar 19, 2024 · 5 comments
Labels
- P2: nice to have Not breaking anything but nice to have (priority) pkg: vercel Related to Vercel adapter (scope)

Comments

@tk04
Copy link
Contributor

tk04 commented Mar 19, 2024

Astro Info

Astro                    v4.5.6
Node                     v20.11.0
System                   macOS (arm64)
Package Manager          npm
Output                   server
Adapter                  @astrojs/vercel/serverless
Integrations             none

If this issue only occurs in one browser, which browser is a problem?

No response

Describe the Bug

When using the @astrojs/vercel integration, I want to exclude a dynamic route from using ISR. Currently, there seems to be no way to do this. All the routes that are passed into the isr.exclude array are matched exactly as is.

for (const route of isrConfig.exclude) {
// vercel interprets src as a regex pattern, so we need to escape it
routeDefinitions.push({ src: escapeRegex(route), dest });
}

What's the expected result?

The processing of the isr.exclude array should offer a way to match dynamic route segments. Therefore, when the code is built, the route src values in the.vercel/output/config.json file should reflect dynamic route segments accordantly.

The strings are currently processed like this:

export function escapeRegex(content: string) {
return `^${getMatchPattern([[{ content, dynamic: false, spread: false }]])}$`;
}

It would be nice to enable dynamic values using /:path or /[path]. A solution might look something like this:

function escapeRegex(content) {
  return `^${getMatchPattern(
    content.split("/").map((value) => [
      {
        content: value,
        dynamic: value.startsWith(":"),
        spread: false,
      },
    ]),
  )}$`;
}

Link to Minimal Reproducible Example

https://stackblitz.com/edit/github-alhqnq?file=astro.config.mjs

Participation

  • I am willing to submit a pull request for this issue.
@github-actions github-actions bot added the needs triage Issue needs to be triaged label Mar 19, 2024
@tk04 tk04 changed the title Match dynamic portions of a route in @astro/vercel isr.exclude array Allow dynamic route segments in @astro/vercel isr.exclude array Mar 19, 2024
@tk04 tk04 changed the title Allow dynamic route segments in @astro/vercel isr.exclude array Allow dynamic route segments in @astrojs/vercel isr.exclude array Mar 19, 2024
@ematipico
Copy link
Member

This sounds more like a feature request, not a bug report.

As far as I remember, ISR accepts regex too.

@ematipico ematipico added needs response Issue needs response from OP pkg: vercel Related to Vercel adapter (scope) labels Mar 19, 2024
@tk04
Copy link
Contributor Author

tk04 commented Mar 19, 2024

The route src values in the config.json file allow regex, but the exclude.isr array doesn't, the values are always escaped:

for (const route of isrConfig.exclude) {
// vercel interprets src as a regex pattern, so we need to escape it
routeDefinitions.push({ src: escapeRegex(route), dest });
}

@lilnasy
Copy link
Contributor

lilnasy commented Mar 19, 2024

The exclude field currently only accepts verbatim paths, but I think it makes sense for it to handle dynamic and spread segments like /[path].

It would work similarly to how configured redirects are processed. We have utilities somewhere that turn /api/[path] into the regular expression /api/([^/]+?).

@lilnasy lilnasy added - P3: minor bug An edge case that only affects very specific usage (priority) - P2: nice to have Not breaking anything but nice to have (priority) and removed needs triage Issue needs to be triaged needs response Issue needs response from OP - P3: minor bug An edge case that only affects very specific usage (priority) labels Mar 19, 2024
@lilnasy
Copy link
Contributor

lilnasy commented Mar 19, 2024

This would be a new feature.

@lilnasy
Copy link
Contributor

lilnasy commented Mar 28, 2024

Implemented in #10513. Thanks @tk04!

@lilnasy lilnasy closed this as completed Mar 28, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
- P2: nice to have Not breaking anything but nice to have (priority) pkg: vercel Related to Vercel adapter (scope)
Projects
None yet
Development

No branches or pull requests

3 participants