SvelteStack / svelte-query

Performant and powerful remote data synchronization for Svelte
https://sveltequery.vercel.app
MIT License
814 stars 31 forks source link

Upgrade to broadcast-channel 4.0 #50

Closed benmccann closed 2 years ago

benmccann commented 2 years ago

Fixes https://github.com/SvelteStack/svelte-query/issues/45. I hope. Note that I've never used svelte-query and haven't tested this. That being said, I got some changes into broadcast-channel that I believe should make it compatible with SvelteKit. You might have to define process.browser if Vite doesn't, but besides that I hope it should just work

dimfeld commented 2 years ago

Thanks for working on this Ben! I'm still seeing problems during Vite SSR phase here, where it tries to load node.js which uses require.

More details below, but I've also created a minimal reproduction here: https://github.com/dimfeld/sveltekit-with-svelte-query. This repo is set up with pnpm and so you can override the version of broadcast-channel used in the pnpm.overrides section of package.json. Hope it helps!

So first I see this error:

ReferenceError: require is not defined
    at /node_modules/.pnpm/broadcast-channel@4.0.0/node_modules/broadcast-channel/src/methods/node.js:6:14
    at instantiateModule (/home/dimfeld/projects/vite/packages/vite/dist/node/chunks/dep-ea6d097e.js:73433:166)

Notably, this is the version in the src directory. I see a comment in the source that it's faster to run the non-transpiled version here, but it does seem to cause issues. If I change the import to the transpiled version (./methods/node.js) then it gets past that, but actually runs into issues with in babel runtime's async transformation code.

ReferenceError: module is not defined
    at /node_modules/.pnpm/@babel+runtime@7.14.8/node_modules/@babel/runtime/helpers/asyncToGenerator.js?v=710ddb8b:35:1
    at instantiateModule (/home/dimfeld/projects/vite/packages/vite/dist/node/chunks/dep-ea6d097e.js:73433:166)
benmccann commented 2 years ago

Thanks for the reproduction. That does help. I'll close this for now

frederikhors commented 2 years ago

I've never used svelte-query

@benmccann why? Can I ask you what are you using right now? Will you ever use it in the future?

benmccann commented 2 years ago

It's nothing against svelte-query. There's just more libraries out there than I've had a chance to use :smile: I may use it in the future

frederikhors commented 2 years ago

Yes, that's what I meant. I just don't know them. Can you tell me what they are?