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

[fix] refactor navigation singletons to avoid storing undefined reference #3374

Merged
merged 4 commits into from Jan 18, 2022

Conversation

pixelmund
Copy link
Contributor

@pixelmund pixelmund commented Jan 16, 2022

This PR fixes #3269, once you import $app/navigation on multiple places inside your app and it's included inside chunks/vendor.js the router would be set before the init function is called and would always be undefined.

Current Bundle:

/// vendor-c70aba79.js
let router$1;
function init(opts) {
  router$1 = opts.router;
}
/// ....
const router = router$1; // Router is undefined and doesnt change on init call
const goto = goto_;
const invalidate = invalidate_;
async function goto_(href, opts) {
  return router.goto(href, opts, []);
}

New Bundle:

let router;
function init(opts) {
  router = opts.router;
}
const goto = goto_;
const invalidate = invalidate_;
async function goto_(href, opts) {
  return router.goto(href, opts, []);
}

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

@netlify
Copy link

netlify bot commented Jan 16, 2022

✔️ Deploy Preview for kit-demo canceled.

🔨 Explore the source changes: 1b77e71

🔍 Inspect the deploy log: https://app.netlify.com/sites/kit-demo/deploys/61e705769474220007f1f3ff

@pixelmund pixelmund changed the title refactor navigation and singletons [fix] #3269 Router not working in production Jan 16, 2022
@pixelmund
Copy link
Contributor Author

Don't know why the test is failing seems not related to this change.

.changeset/brown-mangos-tie.md Outdated Show resolved Hide resolved
packages/kit/src/runtime/client/singletons.js Outdated Show resolved Hide resolved
Co-authored-by: Bjorn Lu <bjornlu.dev@gmail.com>
@changeset-bot
Copy link

changeset-bot bot commented Jan 17, 2022

🦋 Changeset detected

Latest commit: 1b77e71

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

I don't understand how this PR changes anything. If the router is not present when init is called, won't that still be the case?

Also, I'm not sure if it helps, but Vite is removing the vendor chunk: vitejs/vite#6534

@pixelmund pixelmund closed this Jan 17, 2022
@pixelmund pixelmund reopened this Jan 17, 2022
@pixelmund
Copy link
Contributor Author

pixelmund commented Jan 17, 2022

The router const is assigned with the undefined router$1 and the init call only reassigns the router$1 with the actual router. But the const router stays always undefined. This PR removes the const so the reassignment in init works as expected.

Maybe we don't even need this change if the vendor gets removed within vite.

Copy link
Member

@benmccann benmccann left a comment

Choose a reason for hiding this comment

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

Ah, I see. No still seems like a good change to make even on top of the Vite change

@benmccann benmccann changed the title [fix] #3269 Router not working in production [fix] refactor navigation singletons to avoid storing undefined reference Jan 18, 2022
@benmccann benmccann merged commit 86f8f8a into sveltejs:master Jan 18, 2022
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.

Router (goto, invalidate etc.) not working in production
4 participants