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

docs(guides/data-loading): add Cloudflare Pages reference to Cloudflare KV section #3718

Merged
merged 8 commits into from
Jul 14, 2022

Conversation

vorcigernix
Copy link
Contributor

Instructions for Workers were confusing to me when I was figuring out how to set up KV in CF Pages. I hope this could help.

  • [ x ] Docs
  • Tests

Instructions for Workers were confusing to me when I was figuring out how to set up KV in CF Pages. I hope this could help.
@changeset-bot
Copy link

changeset-bot bot commented Jul 13, 2022

⚠️ No Changeset found

Latest commit: 67ec4a3

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

Click here to learn what changesets are, and how to add one.

Click here if you're a maintainer who wants to add a changeset to this PR

@remix-cla-bot
Copy link
Contributor

remix-cla-bot bot commented Jul 13, 2022

Hi @vorcigernix,

Welcome, and thank you for contributing to Remix!

Before we consider your pull request, we ask that you sign our Contributor License Agreement (CLA). We require this only once.

You may review the CLA and sign it by adding your name to contributors.yml.

Once the CLA is signed, the CLA Signed label will be added to the pull request.

If you have already signed the CLA and received this response in error, or if you have any questions, please contact us at hello@remix.run.

Thanks!

- The Remix team

@remix-cla-bot
Copy link
Contributor

remix-cla-bot bot commented Jul 13, 2022

Thank you for signing the Contributor License Agreement. Let's get this merged! 🥳

@machour machour added the docs label Jul 13, 2022
@MichaelDeBoey MichaelDeBoey changed the title Adding Cloudflare Pages docs(guides/data-loading): add Cloudflare Pages reference to Cloudflare KV section Jul 13, 2022
@@ -229,8 +229,40 @@ export default function Product() {
```

## Cloudflare KV
If you picked Cloudflare Pages as your environment, [Cloudflare Key Value][cloudflare-kv] storage allows you to persist data at the edge as if it were a static resource. To start with local development, you need to add a ```--kv``` parameter with a name of your namespace to the package.json task, so it would look like this:
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
If you picked Cloudflare Pages as your environment, [Cloudflare Key Value][cloudflare-kv] storage allows you to persist data at the edge as if it were a static resource. To start with local development, you need to add a ```--kv``` parameter with a name of your namespace to the package.json task, so it would look like this:
If you picked Cloudflare Pages as your environment, [Cloudflare Key Value][cloudflare-kv] storage allows you to persist data at the edge as if it were a static resource. To start with local development, you need to add a `--kv` parameter with a name of your namespace to the package.json task, so it would look like this:

Copy link
Member

@kentcdodds kentcdodds left a comment

Choose a reason for hiding this comment

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

Sorry, I'm confused. It looks like you've duplicated the example 🤔

docs/guides/data-loading.md Outdated Show resolved Hide resolved
docs/guides/data-loading.md Outdated Show resolved Hide resolved
docs/guides/data-loading.md Outdated Show resolved Hide resolved
@vorcigernix
Copy link
Contributor Author

vorcigernix commented Jul 13, 2022 via email

@kentcdodds
Copy link
Member

What is the difference in the code examples?

@vorcigernix
Copy link
Contributor Author

vorcigernix commented Jul 14, 2022 via email

vorcigernix and others added 4 commits July 14, 2022 13:12
Co-authored-by: Kent C. Dodds <me+github@kentcdodds.com>
Co-authored-by: Kent C. Dodds <me+github@kentcdodds.com>
Co-authored-by: Kent C. Dodds <me+github@kentcdodds.com>
Accepted changes and made the description more concise.
```tsx filename=app/routes/products/$productId.tsx
import type { LoaderFunction } from "@remix-run/node"; // or "@remix-run/cloudflare"
import { json } from "@remix-run/node"; // or "@remix-run/cloudflare"
This enable you to use the `PRODUCTS_KV` in a loader context:
Copy link
Member

Choose a reason for hiding this comment

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

Can you show how you get PRODUCTS_KV into the loader context?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The context is initiated on line 245 and it is used on line 248. Pages for some reason require this, while Workers does not.

Copy link
Member

Choose a reason for hiding this comment

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

It's probably better to just generalize this into something about "getLoadContext" is the place where you can pass CF env things through to your action / loader context so it can be applicable to Workers / Pages.

Copy link
Member

Choose a reason for hiding this comment

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

Good point. Do we do the same thing with context for workers? You can get things off of context in that environment as well?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Actually, fixing this behavior to have the same code for both platforms would be great. I consider the Pages code easier to understand though, context explains where the namespace comes from.

docs/guides/data-loading.md Outdated Show resolved Hide resolved
Co-authored-by: Kent C. Dodds <me+github@kentcdodds.com>
Copy link
Member

@kentcdodds kentcdodds left a comment

Choose a reason for hiding this comment

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

Thanks!

docs/guides/data-loading.md Outdated Show resolved Hide resolved
@kentcdodds kentcdodds merged commit 79be9e6 into remix-run:main Jul 14, 2022
@vorcigernix vorcigernix deleted the patch-1 branch July 15, 2022 06:51
mcansh pushed a commit that referenced this pull request Jul 15, 2022
…re KV section (#3718)

Co-authored-by: Kent C. Dodds <me+github@kentcdodds.com>
dvargas92495 pushed a commit to dvargas92495/remix that referenced this pull request Jul 22, 2022
…re KV section (remix-run#3718)

Co-authored-by: Kent C. Dodds <me+github@kentcdodds.com>
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.

5 participants