Index: src/wp-includes/class-wp-network.php
===================================================================
--- src/wp-includes/class-wp-network.php	(revision 42042)
+++ src/wp-includes/class-wp-network.php	(working copy)
@@ -219,10 +219,10 @@
 		 *
 		 * @since 4.9.0
 		 *
-		 * @param int|null $main_site_id If a positive integer is returned, it is interpreted as the main site ID.
-		 * @param int $network_id The ID of the network for which the main site was detected.
+		 * @param int|null   $main_site_id If a positive integer is returned, it is interpreted as the main site ID.
+		 * @param WP_Network $network      The network object for which the main site was detected.
 		 */
-		$main_site_id = (int) apply_filters( 'pre_get_main_site_id', null, $this->id );
+		$main_site_id = (int) apply_filters( 'pre_get_main_site_id', null, $this );
 		if ( 0 < $main_site_id ) {
 			return $main_site_id;
 		}
Index: tests/phpunit/tests/multisite/getMainSiteId.php
===================================================================
--- tests/phpunit/tests/multisite/getMainSiteId.php	(revision 42042)
+++ tests/phpunit/tests/multisite/getMainSiteId.php	(working copy)
@@ -107,6 +107,25 @@
 	}
 
 	/**
+	 * @ticket 29684
+	 */
+	public function test_get_main_site_id_filtered_depending_on_network() {
+		add_filter( 'pre_get_main_site_id', array( $this, 'filter_get_main_site_id_depending_on_network' ), 10, 2 );
+		$result = get_main_site_id( self::$network_ids['wordpress.org/'] );
+
+		$this->assertSame( 333, $result );
+	}
+
+	public function filter_get_main_site_id_depending_on_network( $main_site_id, $network ) {
+		// Override main site ID for a specific network for the test.
+		if ( $network->id === (int) self::$network_ids['wordpress.org/'] ) {
+			return 333;
+		}
+
+		return $main_site_id;
+	}
+
+	/**
 	 * @ticket 41936
 	 */
 	public function test_get_main_site_id_with_property_value() {
