Skip to content

Build error due to link to removed page #314

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

Closed
tomoam opened this issue Apr 4, 2023 · 2 comments · Fixed by #315
Closed

Build error due to link to removed page #314

tomoam opened this issue Apr 4, 2023 · 2 comments · Fixed by #315

Comments

@tomoam
Copy link
Contributor

tomoam commented Apr 4, 2023

When I run pnpm build I get the following error:

Error: 404 /tutorial/ondestroy (linked from /tutorial/auto-subscriptions)

There are two ways to fix it.

  1. remove that link (fix: remove link for removed page #315)
  2. revert removed onDestroy exercise, and make it simpler (chore: simplify the onDestroy exercise #316)

I personally recommend 2, because for someone like me who comes from other programming languages, I learned a lot from the onDestroy exercise.
Indeed, the onDestroy exercises were complex, but I think it can be made simpler.


I have created two different PRs (as Draft just to avoid both being merged).
Please merge the one that is more suitable.

@Rich-Harris
Copy link
Member

Ah, whoops!

I removed the onDestroy exercise after a conversation with the maintainers yesterday — at root, the reason the exercise was so convoluted was that there really aren't many valid use cases for onDestroy. #316 is simpler, but it's still something that doesn't really make sense to do in a real app.

What I've seen in the wild is that people will do this sort of thing:

let thing;

onMount(() => {
  thing = create_thing();
});

onDestroy(() => {
  thing.cleanup();
});

That's not just unnecessarily verbose, it's buggy — in SSR mode, thing will be undefined, because onDestroy is called at SSR time but onMount isn't. In 99% of cases, the setup work should happen in onMount and the cleanup work should happen in the returned callback.

The manual store subscription case is perhaps the one case where it makes sense, but that's really just a limitation of the store API — the fact that you have to subscribe in order to get the value. We're investigating ways to change that in a future version of Svelte, so that we could potentially get rid of onDestroy altogether, but in the meantime we concluded that removing it from the tutorial — as a precursor to deprecating it — is the best solution.

@tomoam
Copy link
Contributor Author

tomoam commented Apr 5, 2023

@Rich-Harris
Thank you for the explanation! It made a lot of sense.

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