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 Automatic cdn invalidation #665

Draft
wants to merge 5 commits into
base: main
Choose a base branch
from

Conversation

conico974
Copy link
Contributor

Fix #658

Still a bit of work to do on this one, it will require a refactor of InternalEvent (or RoutingResult) and the routingHandler so that we have access to the information we need (Or maybe we can use the async hook context)

Copy link

pkg-pr-new bot commented Dec 4, 2024

Open in Stackblitz

pnpm add https://pkg.pr.new/@opennextjs/aws@665

commit: 57a1566

//TODO: test the constructed paths
const constructedPaths = paths.flatMap(({ path, isAppRouter }) =>
isAppRouter
? [`${path}`, `${path}?_rsc=*`]
Copy link
Contributor

@sommeeeer sommeeeer Dec 4, 2024

Choose a reason for hiding this comment

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

I think only ${path}* is enough here? I will do some testing tommorow btw.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It's on purpose ${path}* would invalidate every route that start with path. For example if you have a products and a products/[slug] route (using ${path}*) it would be impossible to invalidate only products

Copy link
Contributor

Choose a reason for hiding this comment

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

I think it also invalidates the products if you use the ${path}* one actually.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

That's not what i'm saying, it invalidates products but also every single products/[slug] route, which may not be what you want

Copy link
Contributor

Choose a reason for hiding this comment

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

but yeah im guessing we dont want that. its probably wise to only invalidate the path.

in my projects im just used to doing the star, cause normally you would want products and products/[slug] invalidated at the same time.

Copy link
Contributor

@sommeeeer sommeeeer Dec 5, 2024

Choose a reason for hiding this comment

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

The paths need to have a leading / else an error will be thrown from cloudfront client: Failed to revalidate tag InvalidArgument: Your request contains one or more invalid invalidation paths.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@sommeeeer It's only for revalidateTag right ? You didn't test res.revalidate ?

Copy link
Contributor

Choose a reason for hiding this comment

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

It's only for revalidateTag right ? You didn't test res.revalidate ?

i tested revalidatePath('/products');

Copy link
Contributor

@sommeeeer sommeeeer Dec 5, 2024

Choose a reason for hiding this comment

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

This works:

const constructedPaths = paths.flatMap(({ path, isAppRouter }) =>
  isAppRouter
    ? [`/${path}`, `/${path}?_rsc=*`]
    : [
        `/${path}`,
        `/_next/data/${process.env.BUILD_ID}${path === "/" ? "/index" : path}.json*`,
      ],
);

Copy link

changeset-bot bot commented Dec 5, 2024

⚠️ No Changeset found

Latest commit: 57a1566

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

This PR includes no changesets

When changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types

Click here to learn what changesets are, and how to add one.

Click here if you're a maintainer who wants to add a changeset to this PR

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.

[Feature] Automatic CDN invalidation for On Demand Revalidation
2 participants