-
-
Notifications
You must be signed in to change notification settings - Fork 2k
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: prevent conflict between Netlify Identity and edge function rendering #12052
fix: prevent conflict between Netlify Identity and edge function rendering #12052
Conversation
Previously Netlify Edge Functions didn't support a way to configure path matching that *excludes* paths. Now that it does, we can avoid running the "render" edge function on static assets. Currently, it's [just a no-op](https://github.com/sveltejs/kit/blob/80386437030c5c79913e859e3c32fd194613e1b6/packages/adapter-netlify/src/edge.js#L18-L22), but it's still nice to avoid the invocation.
🦋 Changeset detectedLatest commit: 42bab13 The changes in this PR will be included in the next version bump. This PR includes changesets to release 1 package
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
e87b06a
to
5c3e74a
Compare
* TODO(serhalp) Replace this custom type with an import from `@netlify/edge-functions`, | ||
* once that type is fixed to include `excludedPath` and `function`. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
FYI I'm working on this as well. I should have a follow-up PR soon.
Hi @benmccann, nice to meet you! Is there anything I need to do to get this PR merged and released? Please let me know. Thanks! |
…erate-edge-functions-that-dont
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sorry for leaving this without a review for so long! From a first glance it looks good. One questions though: What happens if paths.base
(SvelteKit) is set, does that have any influence on this (or in other words would it break)?
@eltigerchino can you have another look at this (checking what happens with a base path, and also investigate whether we can remove the code in is_static_file
?
@@ -13,15 +13,19 @@ import toml from '@iarna/toml'; | |||
*/ | |||
|
|||
/** | |||
* TODO(serhalp) Replace this custom type with an import from `@netlify/edge-functions`, | |||
* once that type is fixed to include `excludedPath` and `function`. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I see that @netlify/edge-functions
does contain excludedPattern
now but not function
- so it looks like we can't use that still.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looking at https://www.npmjs.com/package/@netlify/edge-functions?activeTab=code the ManifestFunction
type contains the correct definition if we want to use those types.
Having a base path seems to work fine with this PR. |
|
||
// Go doesn't support lookarounds, so we can't do this | ||
// const pattern = appDir ? `^/(?!${escapeStringRegexp(appDir)}).*$` : '^/.*$'; | ||
const path = '/*'; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Wonder if we should add the base path to this:
const path = `${builder.config.kit.paths.base}/*`;
const excludedPath = [ | ||
// Contains static files | ||
`/${builder.getAppPath()}/*`, | ||
...builder.prerendered.paths, | ||
...Array.from(assets).flatMap((asset) => { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
the previous logic also checked within manifest._.server_assets
, this one does not - oversight or on purpose?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We could add manifest._.server_assets
too but they're currently already included by the immutable assets exclusion /${builder.getAppPath()}/*
because we copy the server assets over and make them public along with the client assets during the build process. I'm not sure if that will change in the future.
kit/packages/kit/src/exports/vite/index.js
Lines 848 to 851 in f451f6c
copy( | |
`${out}/server/${kit.appDir}/immutable/assets`, | |
`${out}/client/${kit.appDir}/immutable/assets` | |
); |
Fixes #5235.
When using edge functions with Netlify, the generated edge function was configured to run against all paths. This conflicted with the expectation that paths under
.netlify/
(such as.netlify/identity/settings
) are ignored by the framework.At the time #5235 was opened, this was difficult to solve, but Netlify now supports path exclusions in edge function configuration, hence this PR.
While I was here, I also added an exclusion to avoid unnecessarily invoking this edge function on static files. Currently it's just a no-op, but it's still nice to avoid the unnecessary invocation.
Testing this is a bit involved, but I was able to repro the issue in #5235 and to confirm this fixes it. We should probably add proper integration tests here eventually.
Please don't delete this checklist! Before submitting the PR, please make sure you do the following:
Tests
pnpm test
and lint the project withpnpm lint
andpnpm check
Changesets
pnpm changeset
and following the prompts. Changesets that add features should beminor
and those that fix bugs should bepatch
. Please prefix changeset messages withfeat:
,fix:
, orchore:
.Edits