Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

fix(middleware): don't import via entrypoint #12707

Merged
merged 2 commits into from
Dec 10, 2024
Merged

Conversation

ematipico
Copy link
Member

Changes

Closes #12690

The middleware was always imported during the build, even before its execution.

This PR changes that by assigning a function that does the loading.

Testing

CI should pass. I created a new test case. In the test case the middleware imports a file that throws an error at runtime. In the test case the middleware isn't used because all pages SSR, so no errors should be thrown.

Docs

N/A

Copy link

changeset-bot bot commented Dec 10, 2024

🦋 Changeset detected

Latest commit: fc358f3

The changes in this PR will be included in the next version bump.

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

@github-actions github-actions bot added the pkg: astro Related to the core `astro` package (scope) label Dec 10, 2024
Copy link
Member

@florian-lefebvre florian-lefebvre left a comment

Choose a reason for hiding this comment

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

Code looks good, I think it's worth creating a preview release for the user to test

@ematipico
Copy link
Member Author

ematipico commented Dec 10, 2024

I think it's worth creating a preview release for the user to test

Is it, though? I added a test that is the same as the one provided in the issue.

@ematipico
Copy link
Member Author

!preview middleware-fix

Copy link
Contributor

Snapshots have been released for the following packages:

  • astro@experimental--middleware-fix
  • @astrojs/markdown-remark@experimental--middleware-fix
  • @astrojs/markdoc@experimental--middleware-fix
  • @astrojs/mdx@experimental--middleware-fix
Publish Log
🦋  warn ===============================IMPORTANT!===============================
🦋  warn Packages will be released under the experimental--middleware-fix tag
🦋  warn ----------------------------------------------------------------------
🦋  info npm info astro
🦋  info npm info @astrojs/prism
🦋  info npm info @astrojs/rss
🦋  info npm info create-astro
🦋  info npm info @astrojs/db
🦋  info npm info @astrojs/alpinejs
🦋  info npm info @astrojs/markdoc
🦋  info npm info @astrojs/mdx
🦋  info npm info @astrojs/partytown
🦋  info npm info @astrojs/preact
🦋  info npm info @astrojs/react
🦋  info npm info @astrojs/sitemap
🦋  info npm info @astrojs/solid-js
🦋  info npm info @astrojs/svelte
🦋  info npm info @astrojs/tailwind
🦋  info npm info @astrojs/vue
🦋  info npm info @astrojs/web-vitals
🦋  info npm info @astrojs/internal-helpers
🦋  info npm info @astrojs/markdown-remark
🦋  info npm info @astrojs/studio
🦋  info npm info @astrojs/telemetry
🦋  info npm info @astrojs/underscore-redirects
🦋  info npm info @astrojs/upgrade
🦋  info astro is being published because our local version (0.0.0-middleware-fix-20241210163342) has not been published on npm
🦋  warn @astrojs/prism is not being published because version 3.2.0 is already published on npm
🦋  warn @astrojs/rss is not being published because version 4.0.10 is already published on npm
🦋  warn create-astro is not being published because version 4.11.0 is already published on npm
🦋  warn @astrojs/db is not being published because version 0.14.1 is already published on npm
🦋  warn @astrojs/alpinejs is not being published because version 0.4.0 is already published on npm
🦋  info @astrojs/markdoc is being published because our local version (0.0.0-middleware-fix-20241210163342) has not been published on npm
🦋  info @astrojs/mdx is being published because our local version (0.0.0-middleware-fix-20241210163342) has not been published on npm
🦋  warn @astrojs/partytown is not being published because version 2.1.2 is already published on npm
🦋  warn @astrojs/preact is not being published because version 4.0.0 is already published on npm
🦋  warn @astrojs/react is not being published because version 4.0.0 is already published on npm
🦋  warn @astrojs/sitemap is not being published because version 3.2.1 is already published on npm
🦋  warn @astrojs/solid-js is not being published because version 5.0.0 is already published on npm
🦋  warn @astrojs/svelte is not being published because version 7.0.1 is already published on npm
🦋  warn @astrojs/tailwind is not being published because version 5.1.3 is already published on npm
🦋  warn @astrojs/vue is not being published because version 5.0.1 is already published on npm
🦋  warn @astrojs/web-vitals is not being published because version 3.0.1 is already published on npm
🦋  warn @astrojs/internal-helpers is not being published because version 0.4.2 is already published on npm
🦋  info @astrojs/markdown-remark is being published because our local version (0.0.0-middleware-fix-20241210163342) has not been published on npm
🦋  warn @astrojs/studio is not being published because version 0.1.2 is already published on npm
🦋  warn @astrojs/telemetry is not being published because version 3.2.0 is already published on npm
🦋  warn @astrojs/underscore-redirects is not being published because version 0.4.0 is already published on npm
🦋  warn @astrojs/upgrade is not being published because version 0.4.1 is already published on npm
🦋  info Publishing "astro" at "0.0.0-middleware-fix-20241210163342"
🦋  info Publishing "@astrojs/markdoc" at "0.0.0-middleware-fix-20241210163342"
🦋  info Publishing "@astrojs/mdx" at "0.0.0-middleware-fix-20241210163342"
🦋  info Publishing "@astrojs/markdown-remark" at "0.0.0-middleware-fix-20241210163342"
🦋  success packages published successfully:
🦋  astro@0.0.0-middleware-fix-20241210163342
🦋  @astrojs/markdoc@0.0.0-middleware-fix-20241210163342
🦋  @astrojs/mdx@0.0.0-middleware-fix-20241210163342
🦋  @astrojs/markdown-remark@0.0.0-middleware-fix-20241210163342
🦋  Creating git tags...
🦋  New tag:  astro@0.0.0-middleware-fix-20241210163342
🦋  New tag:  @astrojs/markdoc@0.0.0-middleware-fix-20241210163342
🦋  New tag:  @astrojs/mdx@0.0.0-middleware-fix-20241210163342
🦋  New tag:  @astrojs/markdown-remark@0.0.0-middleware-fix-20241210163342
Build Log

> root@0.0.0 build /home/runner/work/astro/astro
> turbo run build --filter=astro --filter=create-astro --filter="@astrojs/*" --filter="@benchmark/*"

• Packages in scope: @astrojs/alpinejs, @astrojs/cloudflare, @astrojs/db, @astrojs/internal-helpers, @astrojs/markdoc, @astrojs/markdown-remark, @astrojs/mdx, @astrojs/netlify, @astrojs/node, @astrojs/partytown, @astrojs/preact, @astrojs/prism, @astrojs/react, @astrojs/rss, @astrojs/sitemap, @astrojs/solid-js, @astrojs/studio, @astrojs/svelte, @astrojs/tailwind, @astrojs/telemetry, @astrojs/underscore-redirects, @astrojs/upgrade, @astrojs/vercel, @astrojs/vue, @astrojs/web-vitals, @benchmark/adapter, @benchmark/timer, astro, create-astro
• Running build in 29 packages
• Remote caching enabled
::group::@astrojs/internal-helpers:build
cache miss, executing 2ee907b552a7ad89

> @astrojs/internal-helpers@0.4.2 build /home/runner/work/astro/astro/packages/internal-helpers
> astro-scripts build "src/**/*.ts" && tsc -p tsconfig.json

::endgroup::
::group::@astrojs/prism:build
cache miss, executing cdca81e1af3fffee

> @astrojs/prism@3.2.0 build /home/runner/work/astro/astro/packages/astro-prism
> astro-scripts build "src/**/*.ts" && tsc -p ./tsconfig.json

::endgroup::
::group::@astrojs/telemetry:build
cache miss, executing cbb575f58666b8ab

> @astrojs/telemetry@3.2.0 build /home/runner/work/astro/astro/packages/telemetry
> astro-scripts build "src/**/*.ts" && tsc

::endgroup::
::group::@astrojs/upgrade:build
cache miss, executing 9062ff56bad9c269

> @astrojs/upgrade@0.4.1 build /home/runner/work/astro/astro/packages/upgrade
> astro-scripts build "src/index.ts" --bundle && tsc

::endgroup::
::group::create-astro:build
cache miss, executing dfdcc70007f81dba

> create-astro@4.11.0 build /home/runner/work/astro/astro/packages/create-astro
> astro-scripts build "src/index.ts" --bundle && tsc

::endgroup::
::group::@astrojs/markdown-remark:build
cache miss, executing 3c7234f39770246f

> @astrojs/markdown-remark@0.0.0-middleware-fix-20241210163342 build /home/runner/work/astro/astro/packages/markdown/remark
> astro-scripts build "src/**/*.ts" && tsc -p tsconfig.json

::endgroup::
::group::astro:build
cache miss, executing 2078f5853e4bdf9a

> astro@0.0.0-middleware-fix-20241210163342 build /home/runner/work/astro/astro/packages/astro
> pnpm run prebuild && astro-scripts build "src/**/*.{ts,js}" --copy-wasm && tsc


> astro@0.0.0-middleware-fix-20241210163342 prebuild /home/runner/work/astro/astro/packages/astro
> astro-scripts prebuild --to-string "src/runtime/server/astro-island.ts" "src/runtime/client/{idle,load,media,only,visible}.ts"

::endgroup::
::group::@benchmark/adapter:build
cache miss, executing d2fa6274d2f25b4d

> @benchmark/adapter@0.0.0 build /home/runner/work/astro/astro/benchmark/packages/adapter
> astro-scripts build "src/**/*.ts" && tsc

::endgroup::
::group::@astrojs/partytown:build
cache miss, executing c6e6d93105ba7e9c

> @astrojs/partytown@2.1.2 build /home/runner/work/astro/astro/packages/integrations/partytown
> astro-scripts build "src/**/*.ts" && tsc

::endgroup::
::group::@benchmark/timer:build
cache miss, executing f6bb0b351ec9ab05

> @benchmark/timer@0.0.0 build /home/runner/work/astro/astro/benchmark/packages/timer
> astro-scripts build "src/**/*.ts" && tsc

::endgroup::
::group::@astrojs/alpinejs:build
cache miss, executing 3cd1a75656db0df9

> @astrojs/alpinejs@0.4.0 build /home/runner/work/astro/astro/packages/integrations/alpinejs
> astro-scripts build "src/**/*.ts" && tsc

::endgroup::
::group::@astrojs/rss:build
cache miss, executing d6a4f4b122b9229a

> @astrojs/rss@4.0.10 build /home/runner/work/astro/astro/packages/astro-rss
> astro-scripts build "src/**/*.ts" && tsc

::endgroup::
::group::@astrojs/svelte:build
cache miss, executing 63f0a59a233434b7

> @astrojs/svelte@7.0.1 build /home/runner/work/astro/astro/packages/integrations/svelte
> astro-scripts build "src/index.ts" && astro-scripts build "src/editor.cts" --force-cjs --no-clean-dist && tsc

::endgroup::
::group::@astrojs/tailwind:build
cache miss, executing cc4e7c0c289b94a1

> @astrojs/tailwind@5.1.3 build /home/runner/work/astro/astro/packages/integrations/tailwind
> astro-scripts build "src/**/*.ts" && tsc

::endgroup::
::group::@astrojs/sitemap:build
cache miss, executing 5e0506ad1a469ff7

> @astrojs/sitemap@3.2.1 build /home/runner/work/astro/astro/packages/integrations/sitemap
> astro-scripts build "src/**/*.ts" && tsc

::endgroup::
::group::@astrojs/mdx:build
cache miss, executing 06c29bdea5b1668b

> @astrojs/mdx@0.0.0-middleware-fix-20241210163342 build /home/runner/work/astro/astro/packages/integrations/mdx
> astro-scripts build "src/**/*.ts" && tsc

::endgroup::
::group::@astrojs/preact:build
cache miss, executing f1c7257d025319bf

> @astrojs/preact@4.0.0 build /home/runner/work/astro/astro/packages/integrations/preact
> astro-scripts build "src/**/*.ts" && tsc

::endgroup::
::group::@astrojs/studio:build
cache miss, executing 5376c3a205f239a4

> @astrojs/studio@0.1.2 build /home/runner/work/astro/astro/packages/studio
> astro-scripts build "src/**/*.ts" && tsc

::endgroup::
::group::@astrojs/underscore-redirects:build
cache miss, executing f908350062461c5e

> @astrojs/underscore-redirects@0.4.0 build /home/runner/work/astro/astro/packages/underscore-redirects
> astro-scripts build "src/**/*.ts" && tsc -p tsconfig.json

::endgroup::
::group::@astrojs/react:build
cache miss, executing f46e0a33328105ae

> @astrojs/react@4.0.0 build /home/runner/work/astro/astro/packages/integrations/react
> astro-scripts build "src/**/*.ts" && tsc

::endgroup::
::group::@astrojs/solid-js:build
cache miss, executing cc57a2b5aa560d37

> @astrojs/solid-js@5.0.0 build /home/runner/work/astro/astro/packages/integrations/solid
> astro-scripts build "src/**/*.ts" && tsc

::endgroup::
::group::@astrojs/vue:build
cache miss, executing d9610980d5c8dbe9

> @astrojs/vue@5.0.1 build /home/runner/work/astro/astro/packages/integrations/vue
> astro-scripts build "src/index.ts" && astro-scripts build "src/editor.cts" --force-cjs --no-clean-dist && tsc

::endgroup::
::group::@astrojs/markdoc:build
cache miss, executing 009d5983ad4cc9ed

> @astrojs/markdoc@0.0.0-middleware-fix-20241210163342 build /home/runner/work/astro/astro/packages/integrations/markdoc
> astro-scripts build "src/**/*.ts" && tsc

::endgroup::
::group::@astrojs/db:build
cache miss, executing 3b24fe3f5fba3aed

> @astrojs/db@0.14.1 build /home/runner/work/astro/astro/packages/db
> astro-scripts build "src/**/*.ts" && tsc && pnpm types:virtual


> @astrojs/db@0.14.1 types:virtual /home/runner/work/astro/astro/packages/db
> tsc -p ./tsconfig.virtual.json

::endgroup::
::group::@astrojs/web-vitals:build
cache miss, executing dc6f563d2f789fa3

> @astrojs/web-vitals@3.0.1 build /home/runner/work/astro/astro/packages/integrations/web-vitals
> astro-scripts build "src/**/*.ts" && tsc

::endgroup::

 Tasks:    25 successful, 25 total
Cached:    0 cached, 25 total
  Time:    46.802s 

Copy link

codspeed-hq bot commented Dec 10, 2024

CodSpeed Performance Report

Merging #12707 will not alter performance

Comparing fix/how-to-load-middleware (fc358f3) with main (3169593)

Summary

✅ 4 untouched benchmarks

@ematipico ematipico merged commit 2aaed2d into main Dec 10, 2024
17 checks passed
@ematipico ematipico deleted the fix/how-to-load-middleware branch December 10, 2024 20:48
This was referenced Dec 10, 2024
# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
pkg: astro Related to the core `astro` package (scope)
Projects
None yet
Development

Successfully merging this pull request may close these issues.

"secret server variables" are validated at build time violating the docs
2 participants