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

generate __data.json files as siblings of .html files #11269

Merged
merged 2 commits into from Dec 12, 2023

Conversation

Rich-Harris
Copy link
Member

This is a possible solution to #8676. It's technically breaking insofar as it clobbers any routes that happen to end with .html__data.json, but given how unlikely that is it's not really breaking.

It solves the problem (that you can't prerender both foo.html and foo.html/__data.json) by making the files siblings — the data is generated as foo.html__data.json instead. This requires no configuration changes, and very little complexity in terms of implementation — no 'is it prerendered?' or 'what do we do with cookies?' questions, just a simple 'does the route end with .html?' check.

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 12, 2023

🦋 Changeset detected

Latest commit: cb6d1ca

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

This PR includes changesets to release 1 package
Name Type
@sveltejs/kit Major

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

@dummdidumm dummdidumm added this to the 2.0 milestone Dec 12, 2023
Copy link
Member

@dummdidumm dummdidumm left a comment

Choose a reason for hiding this comment

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

Makes sense! Although it opens up an edge case bug where cookies doesn't match when it shouldn't. If I'm reading this right then setting a cookie path to /docs.html then it would match /docs.html but not /docs.html__data.json (but it would've previously matched /docs/__data.json). Now I'm not sure if this is really relevant in practise, but it's worth thinking about.

Btw I'm very glad we have this behind helper functions, makes this change really easy

@Rich-Harris
Copy link
Member Author

That's true - perhaps the thing to do is duplicate the cookie in the edge case where a) the route ends with .html and b) the cookie path is identical to the request path

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

Successfully merging this pull request may close these issues.

None yet

2 participants