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: correctly map prerendered pages when base path is set #11245

Merged
merged 2 commits into from
Dec 10, 2023

Conversation

eltigerchino
Copy link
Member

@eltigerchino eltigerchino commented Dec 9, 2023

fixes #11210

Previously, the prerendered manifest didn't set the base path so it looked like this:

export const prerendered = {
  '/base/about': 'about.html'
}

However, this is incorrect because it is stored in the KV with the key /base/about.1asdf34.html (ignore the hash, cloudflare handles it). This is also because we upload the build output such that the public files live in the base folder .cloudflare/public/base/about.html.

Therefore, the new manifest when a base path is set should look like this:

export const prerendered = {
  '/base/about': '/base/about.html'
}

Please don't delete this checklist! Before submitting the PR, please make sure you do the following:

  • It's really useful if your PR references an issue where it is discussed ahead of time. In many cases, features are absent for a reason. For large changes, please create an RFC: https://github.com/sveltejs/rfcs
  • This message body should clearly illustrate what problems it solves.
  • Ideally, include a test that fails without this PR but passes with it.

Tests

  • Run the tests with pnpm test and lint the project with pnpm lint and pnpm check

Changesets

  • If your PR makes a change that should be noted in one or more packages' changelogs, generate a changeset by running pnpm changeset and following the prompts. Changesets that add features should be minor and those that fix bugs should be patch. Please prefix changeset messages with feat:, fix:, or chore:.

Copy link

changeset-bot bot commented Dec 9, 2023

🦋 Changeset detected

Latest commit: 5fa55b6

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

This PR includes changesets to release 1 package
Name Type
@sveltejs/adapter-cloudflare-workers Patch

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

@benmccann
Copy link
Member

It looks like the same change might be needed in other adapters. We should update any affected at the same time, so they don't get out of sync with each other

`export const prerendered = new Set(${JSON.stringify(builder.prerendered.paths)});\n`

@eltigerchino
Copy link
Member Author

eltigerchino commented Dec 9, 2023

It looks like the same change might be needed in other adapters. We should update any affected at the same time, so they don't get out of sync with each other

`export const prerendered = new Set(${JSON.stringify(builder.prerendered.paths)});\n`

I’m not sure if it affects adapter-cloudflare because it doesn’t use the same key value asset mapping handler to return static assets. It just needs a list of pathnames. The builder prerendered paths returned should already include the base path.

I still need to check the other adapters.

@eltigerchino eltigerchino added the paths.base bugs relating to `config.kit.paths.base` label Dec 10, 2023
@eltigerchino
Copy link
Member Author

I don't think the other adapters are affected because they serve the static files like other simple static hosting service (e.g., navigating to /base/about will always return the about.html file). It's only cloudflare workers that needs to be told specifically what pathname it needs to serve the correct file.

As an aside, here are how vercel, netlify, and cloudflare handle multiple projects with the same domain but different base paths.

@Rich-Harris Rich-Harris merged commit c96f622 into master Dec 10, 2023
14 checks passed
@Rich-Harris Rich-Harris deleted the fix-cf-worker-base-prerendered branch December 10, 2023 19:47
@github-actions github-actions bot mentioned this pull request Dec 10, 2023
@elucidsoft
Copy link

This doesn't appear to be fixed. For example, if I set my base to /blog, and then upload to Cloudflare Pages, everything works except anything in the static folder. Everything in static folder is completely inaccessible. The structure of the contents in Cloudflare Pages appears to be correct, the files are there, they are under the subfolder blog, but when I attempt to navigate to them I get a 404. In addition, if I attempt to navigate to them using root, it goes into an infinite refresh loop.

@eltigerchino
Copy link
Member Author

This doesn't appear to be fixed. For example, if I set my base to /blog, and then upload to Cloudflare Pages, everything works except anything in the static folder. Everything in static folder is completely inaccessible. The structure of the contents in Cloudflare Pages appears to be correct, the files are there, they are under the subfolder blog, but when I attempt to navigate to them I get a 404. In addition, if I attempt to navigate to them using root, it goes into an infinite refresh loop.

Just to clarify, are you using the cloudflare adapter or the cloudflare workers adapter? Can you provide a minimal reproduction in a new issue?

@elucidsoft
Copy link

Using the cloudflare adapter. Yes, I could probably get a reproduction working as all I really did was setup a new project with the Cloudflare Adapter, and set the base folder, added some images and a manifest file to static. That was basically it. I'll try to get it repro'd for you and I'll create a new issue. Oh and prerender was set to true.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
paths.base bugs relating to `config.kit.paths.base` pkg:adapter-cloudflare-workers
Projects
None yet
Development

Successfully merging this pull request may close these issues.

CloudFlare Workers Adapter can't serve prerendered pages
4 participants