onDestroy doesn't work in Component Lib in ssr mode
See original GitHub issueDescribe the bug I am making a component lib. In one component (ssr mode) I was using onDestroy (imported from svelte) which called get_current_component().$$.on_destroy.push(fn); where it said on_destroy is undefined. I guess that is a bug?
If I’m abusing the use of generate ssr then that would be an explanation of undefined behavior.
To Reproduce Try creating a component lib (one output contains “generate”: “ssr”, while client output “hydratable”: true) and import the lib into your sapper project.
component lib’s package.json “main” points to the ssr lib while “browser” points to client output.
Expected behavior I don’t expect this error to occur!
Stacktraces
If you have a stack trace to include, we recommend putting inside a <details>
block for the sake of the thread’s readability:
Stack trace
Cannot read property{blah} TypeError: Cannot read property ‘push’ of undefined at onDestroy ({blah}/sapper/dev/server/index-d8e27d9f.js:754:42) at {blah}/sapper/dev/server/index-d8e27d9f.js:927:3 at Object.$$render ({blah}/sapper/dev/server/index-d8e27d9f.js:796:18) at {blah}/sapper/dev/server/index-d8e27d9f.js:1053:54 at Object.$$render ({blah}/sapper/dev/server/index-d8e27d9f.js:81:22) at Object.default ({blah}/sapper/dev/server/index-d8e27d9f.js:308:101) at {blah}/sapper/dev/server/index-d8e27d9f.js:252:38 at Object.$$render ({blah}/sapper/dev/server/index-d8e27d9f.js:81:22) at {blah}/sapper/dev/server/index-d8e27d9f.js:301:41 at $$render ({blah}/sapper/dev/server/index-d8e27d9f.js:81:22).
Information about your Svelte project:
- Your browser and the version: (e.x. Chrome 52.1, Firefox 48.0, IE 10) Firefox 69
- Your operating system: (e.x. OS X 10, Ubuntu Linux 19.10, Windows XP, etc) OS X 10
- Svelte version (Please check you can reproduce the issue with the latest release!) 3.12.1
- Whether your project uses Webpack or Rollup Rollup
Severity How severe an issue is this bug to you? Is this annoying, blocking some users, blocking an upgrade or blocking your usage of Svelte entirely? Not severe at all for my components for now. It blocks use of onDestroy on server side though
Issue Analytics
- State:
- Created 4 years ago
- Comments:7 (1 by maintainers)
For future travelers. having a
svelte: index.js
where index.js exports your components by namein your component library is enough to keep sapper happy, as long as you ensure your component library is installed as a
devDependency
inpackage.json
in your sapper appThanks to some helpful people, think that this is not a bug. Should use bundler only at the top level project not at the component lib level since the bundler will include a copy of svelte at the component level.