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

Fix: 404.html load correctly on preview #9907

Merged
merged 4 commits into from
Feb 2, 2024

Conversation

ktym4a
Copy link
Contributor

@ktym4a ktym4a commented Jan 31, 2024

Changes

Fix: #9854

https://github.com/ktym4a/astro/blob/520be8b113bbb3189033e2952b28a6cda2a676a1/packages/astro/src/core/preview/vite-plugin-astro-preview.ts#L81-L98

I think previous vite404Middleware checks were never happen because next(); is called before that.

so, Moved to be called.

Testing

If this is good, I will add test cases.
but I just need to know where to add test cases.

Docs

don't need to add.

Copy link

changeset-bot bot commented Jan 31, 2024

🦋 Changeset detected

Latest commit: 940f2c6

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 Jan 31, 2024
@ktym4a ktym4a changed the title Fix: 404.index load correctly on preview Fix: 404.html load correctly on preview Jan 31, 2024
@ematipico
Copy link
Member

@ktym4a

I believe this file is a good place to start for testing: https://github.com/withastro/astro/blob/main/packages/astro/test/preview-routing.test.js

You might want to create a use case very similar to what was filed in the issue, and make sure it works

This comment was marked as resolved.

Copy link
Member

@ematipico ematipico left a comment

Choose a reason for hiding this comment

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

Thank you, @ktym4a; the change looks good to me! There is one thing missing: a changeset, then I think we can merge your fix :)

@ktym4a
Copy link
Contributor Author

ktym4a commented Feb 2, 2024

Thanks for your kind support!
I added a changeset.

@ematipico
Copy link
Member

@lilnasy I would love your review here

Copy link
Contributor

@lilnasy lilnasy left a comment

Choose a reason for hiding this comment

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

Looks great to me! Just one question, non-blocking.

Comment on lines +63 to 70
for (const middleware of server.middlewares.stack) {
// This hardcoded name will not break between Vite versions
if ((middleware.handle as Connect.HandleFunction).name === 'vite404Middleware') {
middleware.handle = handle404;
}
}

next();
Copy link
Contributor

Choose a reason for hiding this comment

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

Was it necessary to overwrite vite's middleware during the execution of our other middleware?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@lilnasy
Thanks, I'll do a little research to see if I can move somewhere properly handle vite404Middleware.

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 fine if you don't find it or if it takes too long. This is already quite an improvement!

Copy link
Contributor

Choose a reason for hiding this comment

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

We could add a "// TODO: look into why the replacement needs to happen here" in the meanwhile.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Added TODO comment.
I will research and send another PR if I think it can be improved.
Thank you very much.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@lilnasy lilnasy merged commit 6c894af into withastro:main Feb 2, 2024
12 of 13 checks passed
@astrobot-houston astrobot-houston mentioned this pull request Feb 2, 2024
@ktym4a ktym4a deleted the fix-preview-404 branch February 16, 2024 10:20
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
pkg: astro Related to the core `astro` package (scope)
Projects
None yet
3 participants