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

Add warning when not excluding _app folder in Cloudflare Pages adapter #10454

Closed
wants to merge 8 commits into from

Conversation

LorenzoBloedow
Copy link

Ok so basically, I spent some time trying to debug a bunch of weird 404 errors that were being thrown when I deployed to Cloudflare Pages, after some time I realized it was because I was using a custom exclude array that didn't exclude the _app folder.

For some reason in my deployment I couldn't serve the _app folder from the server so it kept throwing a 404 error.
Initially, I thought of submitting a PR that would always exclude the _app folder, but there's probably a good reason why
SvelteKit allows for the developer to choose, so I thought it'd be nice to log a warning instead so anyone that gets in the same situation can hopefully not get stuck like me.

@changeset-bot
Copy link

changeset-bot bot commented Jul 29, 2023

🦋 Changeset detected

Latest commit: 8541f2c

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 Minor

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

@@ -116,6 +116,13 @@ function get_routes_json(builder, assets, { include = ['/*'], exclude = ['<all>'

return rule;
});

if (!exclude.filter(rule => rule === "<build>" || rule === "/_app/*").length) {
Copy link
Member

Choose a reason for hiding this comment

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

would probably need to check for <all> as well

Copy link
Author

Choose a reason for hiding this comment

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

would probably need to check for <all> as well

That wouldn't work because <all> gets mapped to <build>, <files> and <prerendered>.

This did make me realize that I made a mistake in checking after the mapping, and now the check happens before.
Checking after would mean that <build> would get converted to the app dir so there'd be no reason to check <build> in the first place.

And I was also checking for a hard-coded app directory which would break the check if the default app directory changes.

@benmccann
Copy link
Member

lint is failing and will need to be fixed

Initially, I thought of submitting a PR that would always exclude the _app folder, but there's probably a good reason why
SvelteKit allows for the developer to choose

It looks like the PR implementing the feature originally did that, but @Rich-Harris suggested not to here: #9111 (comment). I'm not too well versed in this feature, but it sounds to me like it's required to exclude _app or else things break. If the only consequence of not excluding it is that your app breaks, I don't see the value in letting users do that. I think it can only result in a poor user experience. But I'm not that familiar with this feature though, so maybe I'm missing something. Thoughts @Rich-Harris?

Copy link
Member

Choose a reason for hiding this comment

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

Woah, what's this file?

'@sveltejs/adapter-cloudflare': minor
---

feat: Log warning when the \_app folder is not excluded
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
feat: Log warning when the \_app folder is not excluded
feat: log warning when the `_app` folder is not excluded

@Rich-Harris
Copy link
Member

okay, re-wrapping my head around the Cloudflare Pages _routes.json config. There's a few things going on here:

  • leaving the app directory out of exclude should be fine — it should just result in an env.ASSETs.fetch here (which results in an unwanted function invocation, but nothing worse than that):
    if (is_static_asset || prerendered.has(pathname)) {
    res = await env.ASSETS.fetch(req);
    } else if (location && prerendered.has(location)) {
    It's not doing that because we (incorrectly) only serve static files and prerendered pages. We can fix that, and when we do, the warning in this PR will be unnecessary
  • In SvelteKit 2, we added a /_app/env.js module which is dynamically generated in certain cases. This must result in a function invocation. We forgot that we need to make sure we only treat certain things inside ${base}/_app (namely immutable and version.json) as static files

IOW we're basically talking about an entirely different chunk of work. I'll open a new PR.

@Rich-Harris
Copy link
Member

closing in favour of #11593 — thanks

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants