-
-
Notifications
You must be signed in to change notification settings - Fork 1.9k
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
Conversation
🦋 Changeset detectedLatest commit: 997d795 The changes in this PR will be included in the next version bump. This PR includes changesets to release 1 package
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 |
Awesome. Thanks! It might not be a bad idea to log a warning if we encounter someone returning |
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 |
Yeah, we can do it dev mode only. Check the mode from |
packages/kit/src/runtime/load.js
Outdated
@@ -52,5 +54,12 @@ export function normalize(loaded) { | |||
} | |||
} | |||
|
|||
if (dev && /** @type {any} */ (loaded).context) { |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ok. That makes sense
Can we safely use |
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. |
Closes #984
Before submitting the PR, please make sure you do the following
Tests
pnpm test
and lint the project withpnpm lint
andpnpm check
Changesets
pnpx changeset
and following the prompts. All changesets should bepatch
until SvelteKit 1.0