svelte-adapter-firebase icon indicating copy to clipboard operation
svelte-adapter-firebase copied to clipboard

bug: Firestore emulation doesn't work with hot reloading

Open slifty opened this issue 3 years ago • 2 comments

Describe the Bug

I think this may be an issue with sveltekit but since this repository represents the blend of sveltekit and firebase it seemed like an appropriate place to document the problem

I have a firebase.ts file configures a connection to firebase. It connects to the emulator if it detects a development environment. This works fine, but if the firebase module is edited while running in development mode / with hot module replacement it results in an error:

Firestore has already been started and its settings can no longer be changed. You can only modify settings before calling any other methods on a Firestore object.

Here is the code just for the record:

const firebaseConfig = {...};

// Initialize Firebase
const app = initializeApp(firebaseConfig);
const db = getFirestore(app);
if (env.NODE_ENV !== 'production') {
	console.log(env);
	console.log('Using Firestore Emulator');
	connectFirestoreEmulator(
		db,
		'localhost',
		8080,
	);
}

Steps to Reproduce

  1. Create a sveltekit project using firebase + an emulator
  2. Run npm run dev
  3. Edit the module that sets up firebase file
  4. Attempt to invoke a firestore transaction
  5. See the error

Expected Behaviour

I would expect the firestore emulation configuration to continue to work.

svelte-adapter-firebase version

0.14.4

sveltejs/kit version

1.0.0-next.488

slifty avatar Oct 11 '22 01:10 slifty

Understood if this ends up being considered irrelevant to this repository, but I thought creating the issue might help others. At this point the only solution I could find is to manually restart npm run dev instead of relying on hot module reloading.

slifty avatar Oct 11 '22 01:10 slifty

I might not be able to actually tackle this issue with the adapter separate from the Firebase framework. Firebase have added official support for Web Frameworks, so this adapter might end up being deprecated if they add support there.

Thanks for sharing your solution / workaround :pray:

jthegedus avatar Dec 14 '22 11:12 jthegedus