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

Middleware intermittently not working on iOS/ARM #8191

Closed
1 task
ZeldOcarina opened this issue Aug 22, 2023 · 50 comments · Fixed by #8614
Closed
1 task

Middleware intermittently not working on iOS/ARM #8191

ZeldOcarina opened this issue Aug 22, 2023 · 50 comments · Fixed by #8614
Labels
- P2: has workaround Bug, but has workaround (priority) feat: middleware Related to middleware (scope)

Comments

@ZeldOcarina
Copy link

What version of astro are you using?

latest

Are you using an SSR adapter? If so, which one?

No

What package manager are you using?

npm

What operating system are you using?

Mac

What browser are you using?

Chrome

Describe the Bug

I have a tried a clean install of Astro with npm create astro@latest but I just cannot get my middleware.ts to run.

I need to pass to components some context data and perform some global transformations on my response data but cannot do that.

What's the expected result?

Middleware running correctly.
Not flagging willing to submit a pull request as I would not know where to start from.

Link to Minimal Reproducible Example

https://github.com/ZeldOcarina/astro-middleware-bug

Participation

  • I am willing to submit a pull request for this issue.
@github-actions github-actions bot added the needs triage Issue needs to be triaged label Aug 22, 2023
@ematipico
Copy link
Member

ematipico commented Aug 22, 2023

I just checked out your repro and I could see the log

Screenshot 2023-08-22 at 17 31 15

If your issue is more specific, please make sure to create a repro for that.

@ZeldOcarina
Copy link
Author

image
Well I don't see it.. :( I am using npm, may that be a factor?

@ZeldOcarina
Copy link
Author

@ematipico I think you closed this a little too hastily.. :(

@ematipico
Copy link
Member

Even with npm, I can see the log. It's essential to be able to replicate the issue. And I am using a mac like you.

@ematipico ematipico reopened this Aug 22, 2023
@natemoo-re
Copy link
Member

natemoo-re commented Aug 22, 2023

Here's a StackBlitz repro, which definitely seems to be working.

@ZeldOcarina could you run npx astro info and node --version and share the output?

@natemoo-re natemoo-re added needs response Issue needs response from OP and removed needs triage Issue needs to be triaged labels Aug 22, 2023
@ZeldOcarina
Copy link
Author

ZeldOcarina commented Aug 22, 2023

Of course!!

mattiarasulo@Host-006 astro-test % npx astro info

Astro version            v2.10.12
Package manager          npm
Platform                 darwin
Architecture             arm64
Adapter                  Couldn't determine.
Integrations             None or couldn't determine.
node --version
v18.15.0

@lilnasy
Copy link
Contributor

lilnasy commented Aug 23, 2023

Couldn't reproduce on windows or linux.

@ematipico
Copy link
Member

@ZeldOcarina it's possible that your terminal doesn't log for some reason. Why don't you try to use it by doing writing something into context.locals, or something else.

@ZeldOcarina
Copy link
Author

Hi! All logs on standard routes etc. work properly. It's only the middleware that is not running at all, it's so weird..
May it be the M1 architecture?

@lilnasy
Copy link
Contributor

lilnasy commented Aug 23, 2023

Did you check if the middleware gets executed?

@ZeldOcarina
Copy link
Author

ZeldOcarina commented Aug 23, 2023

I did by hardcoding some locals and no locals are being passed down to the components etc..

@lilnasy
Copy link
Contributor

lilnasy commented Aug 23, 2023

Could you upload the dist folder somewhere, maybe in a branch.

That would at least rule out an astro bug from something about your environment.

@ZeldOcarina
Copy link
Author

Of course!
I've added the dist folder under the same branch!
Builded the app and removed dist from .gitignore.
Thanks a lot for your help!

@lilnasy
Copy link
Contributor

lilnasy commented Aug 23, 2023

Ah, it's a static build. /dist contains only html, css, and js.

It maybe worth adding an adapter (npm run astro add node) to see if you get the issue in the final build (node dist/server/entry.mjs) as well.

@ZeldOcarina
Copy link
Author

ZeldOcarina commented Aug 23, 2023

Ok done!
Interesting the middleware is called _empty-middleware.mjs for some reason and it's actually empty!
https://github.com/ZeldOcarina/astro-middleware-bug/blob/main/dist/server/_empty-middleware.mjs

@lilnasy
Copy link
Contributor

lilnasy commented Aug 23, 2023

Ok, I see what you see now — not "Request received!".

Building again myself runs the middleware and logs to the console.

Not sure what the issue is. Best guess: you need to reinstall astro, or node. Run npm and other commands in a container if that doesn't work.

@ZeldOcarina
Copy link
Author

That's super weird.. I even tried with Bun and yarn..

@ZeldOcarina
Copy link
Author

I can confirm building in a Codespace container is working.
I think still this should be investigated as it's a very weird behavior..

@lilnasy
Copy link
Contributor

lilnasy commented Aug 23, 2023

It's hard to investigate because as far as I can tell, the cause is is somewhere on your system.

@ZeldOcarina
Copy link
Author

I will try to open a remote M1 from a service I know and see if I can reproduce there.. it may be something that has to do with the ARM architecture..

@ematipico
Copy link
Member

ematipico commented Aug 23, 2023

I think the best course of action is creating a thread on discord, in the support channel, and chat with people there.

This seems to be an issue specific to someone machine/environment and unfortunately it's very hard to debug unless you do it yourself from the source code.

I have a M2 and I can't see this issue. Weird.

@ZeldOcarina
Copy link
Author

Ha I got it!
Bug happens only if I clone the repo on my external SSD, won't happen on my main drive.
Do you have an external disk you can try it on @ematipico?

@ematipico
Copy link
Member

I don't think there's much we can do. This is something related to your machine and environment, I can't look for an external hard drive 😅

@natemoo-re
Copy link
Member

Wow that is very strange! I have no idea what could be causing this problem when running on an external SSD. I agree that there's probably not much we can do, since it seems so environment specific... I tried searching through Vite, Rollup, Node issues but can't seem to find anything similar to this either.

@lilnasy
Copy link
Contributor

lilnasy commented Aug 23, 2023

There is this one issue: #8164 (comment).

@ZeldOcarina ZeldOcarina reopened this Sep 20, 2023
@github-actions github-actions bot added the needs triage Issue needs to be triaged label Sep 20, 2023
@lilnasy lilnasy added the needs repro Issue needs a reproduction label Sep 20, 2023
@github-actions
Copy link
Contributor

Hello @ZeldOcarina. Please provide a minimal reproduction using a GitHub repository or StackBlitz. Issues marked with needs repro will be closed if they have no activity within 3 days.

@github-actions github-actions bot removed the needs triage Issue needs to be triaged label Sep 20, 2023
@ZeldOcarina
Copy link
Author

@lilnasy I think you do have a reproduction repo, let's not be too picky on that.. issue should not be closed..

@lilnasy
Copy link
Contributor

lilnasy commented Sep 20, 2023

So far I thought the linked repo would reproduce the issue on an external disk. But if someone is encountering the bug without it, there's probably another factor to consider.

Either way, I marked it as need repro because it's not an actionable issue, it's just going to sit here.

@lilnasy lilnasy removed the needs repro Issue needs a reproduction label Sep 20, 2023
@ZeldOcarina
Copy link
Author

Ok thanks! :)

@WinnieS0728
Copy link

here is my install detail

  • type npm create astro@latest in folder terminal, and choose some setting.

image

i get this dependencies in package.json

  "dependencies": {
    "astro": "^3.1.1"
  }
  • add middleware.ts inside src folder

  • type tree -I node_modules and now my project look like this.

image

  • inside middleware.ts export a onRequest function
import { defineMiddleware } from "astro:middleware";

export const onRequest = defineMiddleware((context,next)=>{
    console.log('middleware');

    return next()
}) 
  • inside pages > index.astro add console.log('page') in frontmatter

  • run npm run dev and go to http://localhost:4321/

now i got this issue

image

no 'middleware' but only 'page' in terminal log

seems like my onRequest didn't work 🫠.

did i miss any step or do anything wrong ??

I publish this folder to a github repo.

github repo link

can anyone test if this is my personal issue.

thanks for reading this long post.

glad to get any advice.

@lilnasy
Copy link
Contributor

lilnasy commented Sep 21, 2023

@WinnieS0728 Pretty sure it's something about your (and ZeldOcarina's) system.
image

@WinnieS0728
Copy link

well i just create a new folder and do

  • type git clone https://github.com/WinnieS0728/middleware-demo

  • cd ./middleware-demo

  • npm i

  • npm start

still got same issue.

image

but when i do these same step inside my github folder

and look what i got

image

now thing become SUPER WIERD 🤣

@lilnasy
Copy link
Contributor

lilnasy commented Sep 21, 2023

@WinnieS0728 Your investigation might be really helpful!

You have traditional chinese characters in the path in the first case where you encounter the issue.

Could you post a screenshot where you run the pwd command in both cases?

And see if adding a chinese character to the GitHub directory name breaks it as well.

@WinnieS0728
Copy link

WinnieS0728 commented Sep 21, 2023

chinese characters new folder

pwd
/Users/winnie.chang/Desktop/未命名檔案夾

result
image

english characters new folder

pwd
/Users/winnie.chang/Desktop/new folder

result
image

chinese characters new folder in github folder

pwd
/Users/winnie.chang/Documents/GitHub/未命名檔案夾

result
image

english characters new folder in github folder

pwd
/Users/winnie.chang/Documents/GitHub/new folder in github

result
image

direct inside github folder

pwd
/Users/winnie.chang/Documents/GitHub

result
image

seems like only work direct inside github folder

@lilnasy
Copy link
Contributor

lilnasy commented Sep 21, 2023

english characters new folder in github folder
pwd
/Users/winnie.chang/Documents/GitHub/new folder in github

Could you remove spaces from this folder. Maybe /Users/winnie.chang/Documents/GitHub/new/.

@WinnieS0728
Copy link

new folder without space in github folder

pwd
/Users/winnie.chang/Documents/GitHub/new

result
image

new folder without space

pwd
/Users/winnie.chang/Desktop/newFolder

result
image

i think you just resolve the issue 🥳.

@lilnasy
Copy link
Contributor

lilnasy commented Sep 21, 2023

@ZeldOcarina Is there a space in the full path in your project?

@lilnasy
Copy link
Contributor

lilnasy commented Sep 21, 2023

I can reproduce the issue on linux. middleware-demo -> "middleware demo" (with space)
image

@lilnasy lilnasy added - P2: has workaround Bug, but has workaround (priority) feat: middleware Related to middleware (scope) and removed needs response Issue needs response from OP labels Sep 21, 2023
@WinnieS0728
Copy link

so i think maybe is not personal issue ?

I don't know about detail, but I'm guessing is something like astro compiler detect folder name when build running env can't read space or chinese ?

@lilnasy
Copy link
Contributor

lilnasy commented Sep 21, 2023

@WinnieS0728 The fix in #8614 should work for chinese characters as well.

@WinnieS0728
Copy link

how about the space.

in my case i typed space almost 80% of my project if name have more than 1 words.

the chinese characters '未命名檔案夾' is means 'unnamed folder', and it's the default name when create a new folder in my mac.

i almost never use chinese characters in my projects.

@lilnasy
Copy link
Contributor

lilnasy commented Sep 21, 2023

Both spaces and non-english characters are fixed.

@WinnieS0728
Copy link

Thank you so so so much.

I search this issue almost a day around google, youtube and even Bing AI.

no one have same issue 🫠.

thanks for your help.

@lilnasy
Copy link
Contributor

lilnasy commented Sep 21, 2023

Thank you, you're the one who figured what the problem even is! Fixing is the easy part.

@ZeldOcarina
Copy link
Author

whoo whoo thanks a bunch @lilnasy @WinnieS0728 !
Yes there was some blank spaces in my OS. Sorry if the issue name was misleading, we made it!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
- P2: has workaround Bug, but has workaround (priority) feat: middleware Related to middleware (scope)
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants