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

[🐛 Bug]: next-on-pages repeatedly appends to _headers #848

Closed
1 task
nickbabcock opened this issue Aug 4, 2024 · 0 comments · Fixed by #851
Closed
1 task

[🐛 Bug]: next-on-pages repeatedly appends to _headers #848

nickbabcock opened this issue Aug 4, 2024 · 0 comments · Fixed by #851
Labels
bug Something isn't working

Comments

@nickbabcock
Copy link
Contributor

nickbabcock commented Aug 4, 2024

next-on-pages environment related information

System:
        Platform: linux
        Arch: x64
        Version: #41~22.04.2-Ubuntu SMP PREEMPT_DYNAMIC Mon Jun  3 11:32:55 UTC 2
        CPU: (12) x64 AMD Ryzen 9 5900X 12-Core Processor
        Memory: 20 GB
        Shell: /bin/bash
Package Manager Used: npm (10.5.0)

Relevant Packages:
        @cloudflare/next-on-pages: 1.13.1
        vercel: N/A
        next: 14.2.5

Description

Each invocation of:

npx @cloudflare/next-on-pages@1

Appends another instance of:

# === START AUTOGENERATED @cloudflare/next-on-pages IMMUTABLE HEADERS ===
/_next/static/*
  cache-control: public,max-age=31536000,immutable
# === END AUTOGENERATED @cloudflare/next-on-pages IMMUTABLE HEADERS ===

to public/_headers. Which doesn't seem right. I would expect only .vercel/output/static/_headers to contain the auto generated content and not public/_headers too

Reproduction

npx create-next-app@latest my-next-app
cd my-next-app
npm install -D @cloudflare/next-on-pages
touch public/_headers
npx @cloudflare/next-on-pages@1
cat public/_headers

Pages Deployment Method

None

Pages Deployment ID

No response

Additional Information

The bug is due to vercel hardlinking public assets directory.

https://github.com/vercel/vercel/blob/8e20fed2769ff0169179d2d40fcc97cfd07a8bfe/packages/gatsby-plugin-vercel-builder/src/helpers/static.ts#L15

Perhaps next-on-pages takes matters into their own hands with the equivalent of:

# vercel build ...
[[ -f public/_headers ]] && cp --remove-destination public/_headers .vercel/output/static/_headers
echo "AUTOGENERATED ..." >> .vercel/output/static/_headers

Would you like to help?

  • Would you like to help fixing this bug?
@nickbabcock nickbabcock added the bug Something isn't working label Aug 4, 2024
nickbabcock added a commit to nickbabcock/next-on-pages that referenced this issue Aug 5, 2024
Vercel hard links the public directory so when next-on-pages appends to
the vercel output directory, it is also appending to the original
`public/_headers` file too.

This commit fixes the problem by copying the contents to memory before
unlinking the file and creating a new (non-linked) file.

I was able to test out this patch and saw it worked for when `_headers`
exists and when it is absent.

Closes cloudflare#848
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant