- Notifications
You must be signed in to change notification settings - Fork96
[do not merge] exploring adapters API#3136
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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.
Already on GitHub?Sign in to your account
Draft
pieh wants to merge82 commits intomainChoose a base branch fromwip-adapter
base:main
Could not load branches
Branch not found:{{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline, and old review comments may become outdated.
Uh oh!
There was an error while loading.Please reload this page.
Draft
Changes fromall commits
Commits
Show all changes
82 commits Select commitHold shift + click to select a range
2afe782 auto setup dummy adapter
piehcee330c use modifyConfig to set standalone output
pieh0fe7e9a setup loaderFile for next/image and avoid a rewrite
piehebf1407 test: run canary tests to use most recent adapters API
pieh15e64f2 fixup! setup loaderFile for next/image and avoid a rewrite
piehce070d6 move setting up remote images config to adapter
pieh273fd1c refactor adapter a bit and start creating modules per concern
pieha698e1b move legacy ipx redirect to adapter as well
piehc4bf5e3 skip retries in CI for now
pieh4df59c1 type frameworks api config
pieh66cd37f only set standalone if output is not export
pieh6c46c9d migrate immutable headers for next/static
pieh0c24a46 testing out static file copying
mrstork9f371fd remove no longer used
pieh4816bc3 maybe fix __vite_ssr_import_meta__ problems
pieh303ff66 link to vitest issue
pieh650e534 move edge middleware setup to adapter
pieh0e4bee3 remove unit test for deleted copyStaticAssets
piehf369128 fix lint
pieh204cb66 update notes
pieh1799786 test: adjust tests to look for .netlify/images and not _next/image
pieh242d71f lets try to annotate some tests to see if it helps with finding commo…
piehbffff19 add missing name and generator to middleware EF
pieh3bf80ae handle node middleware
pieh1a7e93d remove no longer used build plugin middleware handling
pieh36dc9db rename step
mrstorka42a9b8 move static content step to adapter pattern
mrstork5b436e2 actually static-content step is not needed
mrstorke140441 mark middleware handling as done
pieh3f76a9f add note/question about export output
pieh2341079 preserve html extension for static files
pieh98c8e76 add links to repro for i18n problems
pieh17e5f50 split feedback and notes for us
pieh0305db3 add note about static files and trailingSlash config
pieha298b3b remove next patching as we don't use that for newer next versions
pieh5215cf8 static assets trailing slashes, public and some constants moving
piehb19d48e fix lint
piehcc9eaab workaround: create empty static json for fully static pages
pieh8365f8c ignore some files
pieh20e65cc move .vercel gitignore to the root
piehefe9901 generate pages and app handler from adapters and not standalone
piehef37f11 refactor: separate build-time and run-time concerns for adapter
piehfb49bea introduce netlify adapter context for reusable helpers
pieh7cdda4f br
pieh21147c6 Merge remote-tracking branch 'origin/main' into wip-adapter-full
piehb62c819 chore: bump next-with-adapters version to get up to date types
pieh1208aa4 ci: disable integration tests as setup was not updated
piehccb1b9d tmp: use locally patched cli
pieh0582782 test: skip skew protection / buildbot tests
pieh07d3a82 get more routes node output from prerenders
piehb029575 restore headers we use to set to try to produce output compatible for…
pieh1062a41 chore: move image loader to shared dir
pieh4d4cad6 fix: use typed inline configs for produced functions
pieh268c79c fix: ntl serve compat
piehebb839d more ntl serve compat + some routing adjustments
piehf3e466e fix next-with-adapters bump
pieh73c6bb9 simplify redirect handling with sourceRegex shipped recently in adapt…
piehda1494f support dynamic routes
pieh3b3b439 Merge remote-tracking branch 'origin/main' into wip-adapter-full
piehc4651fe fix middleware
pieh6392918 normalize index at build time
pieh7e71d20 rsc start
piehf44bd01 add hit routing rules
pieha37aa12 allow non-next js routes to match
piehda090ce fix response header and applied header merging (fixes redirects that …
pieh2365301 use buildId from adapter context and don't read on our own
piehd4d4e59 fix: lowercase nf paths
piehac23f0d i18n rewrite to default locale if path is not locale prefixed
pieh867f7ef missing src path for __next_data_catchall
pieh2e15e26 adjust catchall
pieh0438780 fix rule evaluation continuation
piehd055699 middleware simplification and unification with routing EF
piehbefe21a more
piehfe6ca5f middleware + fully static workaround
pieh49b8a41 Merge remote-tracking branch 'origin/main' into wip-adapter-full
piehb574520 middleware matcher routes
piehb9daa5a continue on auto-i18n default locale prefixing
pieh0b07f5d remove no longer needed patch-package
piehd0a41f9 initial scaffolding for revalidation
pieh9435972 fix cases without middleware
pieh36a877b initial isr
pieh668c2f2 routing doc
piehFile filter
Filter by extension
Conversations
Failed to load comments.
Loading
Uh oh!
There was an error while loading.Please reload this page.
Jump to
Jump to file
Failed to load files.
Loading
Uh oh!
There was an error while loading.Please reload this page.
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -22,3 +22,6 @@ tests/**/package-lock.json | ||
| tests/**/pnpm-lock.yaml | ||
| tests/**/yarn.lock | ||
| tests/**/out/ | ||
| # Local Vercel folder | ||
| .vercel | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,53 @@ | ||
| ## Feedback | ||
| - Files from `public` directory not listed in `outputs.staticFiles`. Should they be? | ||
| - `routes.headers` does not contain immutable cache-control headers for `_next/static`. Should those | ||
| be included? | ||
| - In `onBuildComplete` - `config.images.remotePatterns` type is `(RemotePattern | URL)[]` but in | ||
| reality `URL` inputs are converted to `RemotePattern` so type should be just `RemotePattern[]` in | ||
| `onBuildComplete` (this would require different config type for `modifyConfig` (allow inputs | ||
| here?) and `onBuildComplete` (final, normalized config shape)?) | ||
| - `outputs.middleware.config.matchers` can be undefined per types - can that ever happen? Can we | ||
| just have empty array instead to simplify handling (possibly similar as above point where type is | ||
| for the input, while "output" will have a default matcher if not defined by user). | ||
| - `outputs.middleware` does not contain `env` that exist in `middleware-manifest.json` (i.e. | ||
| `NEXT_SERVER_ACTIONS_ENCRYPTION_KEY`, `NEXT_PREVIEW_MODE_ID`, `NEXT_PREVIEW_MODE_SIGNING_KEY` etc) | ||
| or `wasm` (tho wasm files are included in assets, so I think I have a way to support those as-is, | ||
| but need to to make some assumption about using extension-less file name of wasm file as | ||
| identifier) | ||
| - `outputs.staticFiles` (i18n enabled) custom fully static (no `getStaticProps`) `/pages/*` | ||
| `filePath` point to not existing file - see repro at https://github.com/pieh/i18n-adapters | ||
| - `outputs.staticFiles` (i18n enabled) custom `/pages/*` with `getStaticProps` result in fatal | ||
| `Error: Invariant: failed to find source route /en(/*) for prerender /en(/*)` directly from | ||
| Next.js: | ||
| ``` | ||
| ⨯ Failed to run onBuildComplete from Netlify | ||
| > Build error occurred | ||
| Error: Invariant: failed to find source route /en/404 for prerender /en/404 | ||
| ``` | ||
| (additionally - invariant is reported as failing to run `onBuildComplete` from adapter, but it | ||
| happens before adapter's `onBuildComplete` runs, would be good to clear this up a bit so users | ||
| could report issues in correct place in such cases. Not that important for nearest future / not | ||
| blocking). | ||
| See repro at https://github.com/pieh/i18n-adapters (it's same as for point above, need to | ||
| uncomment `getStaticProps` in one of the pages in repro to see this case) | ||
| - `output: 'export'` case seems to produce outputs as if it was not export mode (for example having | ||
| non-empty `outputs.appPages` or `outputs.prerenders`). To not have special handling for that in | ||
| adapters, only non-empty outputs should be `staticFiles` pointing to what's being written to `out` | ||
| (or custom `distDir`) directory? | ||
| - `output.staticFiles` entries for fully static pages router pages don't have `trailingSlash: true` | ||
| option applied to `pathname`. For example: | ||
| ```json | ||
| { | ||
| "id": "/link/rewrite-target-fullystatic", | ||
| "//": "Should pathname below have trailing slash, if `trailingSlash: true` is set in next.config.js?", | ||
| "pathname": "/link/rewrite-target-fullystatic", | ||
| "type": "STATIC_FILE", | ||
| "filePath": "/Users/misiek/dev/next-runtime-adapter/tests/fixtures/middleware-pages/.next/server/pages/link/rewrite-target-fullystatic.html" | ||
| } | ||
| ``` |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,32 @@ | ||
| ## Plan | ||
| 1. There are some operations that are easier to do in a build plugin context due to helpers, so some | ||
| handling will remain in build plugin (cache save/restore, moving static assets dirs for | ||
| publishing them etc). | ||
| 2. We will use adapters API where it's most helpful: | ||
| - adjusting next config: | ||
| - [done] set standalone mode instead of using "private" env var (for now at least we will continue | ||
| with standalone mode as using outputs other than middleware require bigger changes which will be | ||
| explored in later phases) | ||
| - [done] set image loader (url generator) to use Netlify Image CDN directly (no need for | ||
| \_next/image rewrite then) | ||
| - (maybe/explore) set build time cache handler to avoid having to read output of default cache | ||
| handler and convert those files into blobs to upload later | ||
| - [done] use middleware output to generate middleware edge function | ||
| - [done] don't glob for static files and use `outputs.staticFiles` instead | ||
| - [checked, did not apply changes yet, due to question about this in feedback section] check | ||
| `output: 'export'` case | ||
| - note any remaining manual manifest files reading in build plugin once everything that could be | ||
| adjusted was handled | ||
| ## To figure out | ||
| - Can we export build time otel spans from adapter similarly how we do that now in a build plugin? | ||
| - Expose some constants from build plugin to adapter - what's best way to do that? (things like | ||
| packagePath, publishDir etc) | ||
| - Looking forward - Platform change to accept a list of files to upload to cdn (avoids file system | ||
| operations such as `cp`) | ||
| - Looking forward - allow using regexes for static headers matcher (needed to apply next.config.js | ||
| defined headers to apply to static assets) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -28,9 +28,6 @@ yarn-error.log* | ||
| # local env files | ||
| .env*.local | ||
| # typescript | ||
| *.tsbuildinfo | ||
| next-env.d.ts | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,132 +1,30 @@ | ||
| import type { Context } from '@netlify/edge-functions' | ||
| import type { RequestData } from './types' | ||
| export const buildNextRequest = ( | ||
| request: Request, | ||
| nextConfig: RequestData['nextConfig'], | ||
| ): RequestData => { | ||
| const { url, method, body, headers } = request | ||
| // we don't really use it but Next.js expects a signal | ||
| const abortController = new AbortController() | ||
| return { | ||
| headers: Object.fromEntries(headers.entries()), | ||
| method, | ||
| nextConfig, | ||
| // page?: { | ||
| // name?: string; | ||
| // params?: { | ||
| // [key: string]: string | string[] | undefined; | ||
| // }; | ||
| // }; | ||
| url, | ||
| body: body ?? undefined, | ||
| signal: abortController.signal, | ||
| /** passed in when running in edge runtime sandbox */ | ||
| // waitUntil?: (promise: Promise<any>) => void; | ||
| } | ||
| } |
Oops, something went wrong.
Uh oh!
There was an error while loading.Please reload this page.
Oops, something went wrong.
Uh oh!
There was an error while loading.Please reload this page.
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.