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

SSR behaviour different with hybrid mode and node adapter between Linux and MacOS (ARM) #11232

Closed
1 task
LunaticMuch opened this issue Jun 11, 2024 · 6 comments · Fixed by #11243
Closed
1 task
Labels
- P3: minor bug An edge case that only affects very specific usage (priority)

Comments

@LunaticMuch
Copy link
Contributor

Astro Info

Astro                    v4.10.1
Node                     v20.11.1
System                   macOS (arm64)
Package Manager          npm
Output                   hybrid
Adapter                  @astrojs/node
Integrations             @astrojs/starlight
                         @astrojs/tailwind

Describe the Bug

I recently opened an issue with Astro Starlight because I was seeing a weird behaviour with SSR.
In building the test case, I've noticed that the issue can be reproduced on MacOS (ARM) but not on codesandbox (or stackblitz) with Linux. It pointed me out to further debug and potentially rule out Starlight, and consider that the issue is within the adapter or compiler somewhere 😕

None of the pages included in starlight are pre-rendered when the build runs on MacOS. They should be prerendered.
However, when the build runs on Linux, they all get pre-rendered.

I tried different version of nodes too, as the default one in Stackblitz is v18 and I was running on v20, but this has not change anything.

In trying to reproduce, I collected logs and committed into my repo. Look for the following

What's the expected result?

The result is that the pages in starlight plugin get pre-rendered too. There's no reason for not rendering then and, given the hybrid configuration, by default they should be rendered.

Link to Minimal Reproducible Example

https://stackblitz.com/~/github.com/LunaticMuch/fuzzy-giggle

Participation

  • I am willing to submit a pull request for this issue.
@alexanderniebuhr alexanderniebuhr transferred this issue from withastro/adapters Jun 11, 2024
@github-actions github-actions bot added the needs triage Issue needs to be triaged label Jun 11, 2024
@V3RON
Copy link
Contributor

V3RON commented Jun 11, 2024

That's weird. I cloned you repository, try building it myself and experienced no issues at all, no matter which Node version I used (v18, v20, v21).

Astro                    v4.10.1
Node                     v18.20.3
System                   macOS (arm64)
Package Manager          unknown
Output                   hybrid
Adapter                  @astrojs/node
Integrations             @astrojs/starlight
                         @astrojs/tailwind

See full logs here

Is there anything special about your environment? Could you purge node_modules, reinstall and try again? 🤔

@LunaticMuch
Copy link
Contributor Author

Is there anything special about your environment? Could you purge node_modules, reinstall and try again? 🤔

Just tried on one of my laptop, fresh clone and npm cache clean --force before running npm ci, I get this

 prerendering static routes 
17:50:42 ▶ src/pages/schema/[...slug].astro
17:50:42   ├─ /schema/1/index.html (+10ms)
17:50:42   ├─ /schema/2/index.html (+3ms)
17:50:42   └─ /schema/3/index.html (+3ms)
17:50:42 ✓ Completed in 32ms.

So no change. I do not think I have anything weird on my env. I use nvm for managing my node versions, but other than that I do not have any NODE_ variable set.

@V3RON
Copy link
Contributor

V3RON commented Jun 11, 2024

@LunaticMuch

Aha! I reproduced it 🚀

I noticed the directory where Astro is running on your side includes "_GITHUB." I added the same directory on my side, and voilà, I observed the same behavior.

I'll investigate it further today and provide a detailed explanation.

@LunaticMuch
Copy link
Contributor Author

I noticed the directory where Astro is running on your side includes "_GITHUB." I added the same directory on my side, and voilà, I observed the same behavior.

I have my path as /Users/stefano/_GITHUB but initially I observed the behaviour in a different path.

@V3RON
Copy link
Contributor

V3RON commented Jun 11, 2024

That's the culprit:

function isPublicRoute(file: URL, config: AstroConfig): boolean {
const pagesDir = resolvePages(config);
const parts = file.toString().replace(pagesDir.toString(), '').split('/').slice(1);
for (const part of parts) {
if (part.startsWith('_')) return false;
}
return true;
}

Notice the condition in line 124. It checks for the presence of _ in any part of the URL. The problem is that file is an absolute path, so _GITHUB is picked up by this condition, causing the page to be considered 'not public'.

We should limit paths to the repository root.

EDIT: I'm working on a fix now. It's nearly ready 🔥

@LunaticMuch
Copy link
Contributor Author

We should limit paths to the repository root.
Yeah, it should the local path and not the file path... I was about to propose a fix, but thanks 😄

@bluwy bluwy added - P3: minor bug An edge case that only affects very specific usage (priority) and removed needs triage Issue needs to be triaged labels Jun 12, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
- P3: minor bug An edge case that only affects very specific usage (priority)
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants