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

[breaking] rename context param of load to stuff #2439

Merged
merged 8 commits into from
Sep 22, 2021
Merged

[breaking] rename context param of load to stuff #2439

merged 8 commits into from
Sep 22, 2021

Conversation

dummdidumm
Copy link
Member

Closes #984

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 pnpx changeset and following the prompts. All changesets should be patch until SvelteKit 1.0

@changeset-bot
Copy link

changeset-bot bot commented Sep 16, 2021

🦋 Changeset detected

Latest commit: 997d795

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 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

Awesome. Thanks!

It might not be a bad idea to log a warning if we encounter someone returning context from their load function. We're getting close enough to 1.0 now and Kit has almost as many users as Sapper that it might be nice to help folks out a bit with stuff like this eventhough we're still in beta

@Conduitry
Copy link
Member

Do we have the ability to do that in dev mode only?

Alternatively, is there a reasonable way to check for that only during SSR? It is a nice warning to be able to give people, but I don't want to be sending extra bytes to browsers.

Also alternatively, should it always be a warning/error to return any unknown keys from the load function, long-term, not just this one that we're renaming?

@benmccann
Copy link
Member

Yeah, we can do it dev mode only. Check the mode from $env or import.meta.env.DEV and Rollup/Vite will remove it from production build

@@ -52,5 +54,12 @@ export function normalize(loaded) {
}
}

if (dev && /** @type {any} */ (loaded).context) {
Copy link
Member Author

Choose a reason for hiding this comment

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

Added the warning. Using dev from ./app/env here, which wasn't used anywhere else yet (only for user-facing-code), hope that doesn't have any bad implications.

Copy link
Member Author

Choose a reason for hiding this comment

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

Well, it does apperently, tests are failing now because env is not set in tests. What now?

Copy link
Member

Choose a reason for hiding this comment

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

Would context still work in prod? If not I think we should make a hard error here.

But regarding the error, I believe it's because import.meta.env is non-standard in nodejs so it would resolve to undefined, hence the error. A workaround is to shim it with import.meta.env = { /* ... */ } at the top of this file, though we need to make sure we do that for tests only. Using process.env.NODE_ENV may be fine for this as well.

Copy link
Member

Choose a reason for hiding this comment

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

I'd expect it to be defined in the integration tests. I think the issue is around this being unit tested. Rather than modify this to shim it, I wonder if we could move the check to another location that's called in integration tests, but not unit tests.

Copy link
Member Author

Choose a reason for hiding this comment

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

This sounds wrong to me. I picked this method as it seems the central location to validating the load response. Also we probably don't have this check in for long, we could remove it at 1.0 and before that shimming it sounds like a pragmatic solution in the meantime

Copy link
Member

Choose a reason for hiding this comment

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

Ok. That makes sense

@dummdidumm
Copy link
Member Author

Can we safely use import.meta.env in all Kit code that is run by the user? If so, is the failure of the tests only a hint for us to provide these import.meta.env definitions?

@dummdidumm
Copy link
Member Author

I failed to come up with a way to set this that is both tree shakeable and doesn't require us to introduce esm import mocking into the unit tests, so I just left the error in - it will be shipped now every time (sorry @Conduitry ). I think this is okay since we will throw it out in a couple of weeks anyway.

@benmccann benmccann merged commit 490e3d9 into master Sep 22, 2021
@benmccann benmccann deleted the stuff branch September 22, 2021 22:35
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.

Rename context to stuff
4 participants