Background
If, for example, you want to show a survey after a user has completed an action (including outside of mainspace), then you have to use QuickSurveys' showSurvey() method:
const require = await mw.loader.using( 'ext.quicksurveys.lib' ); require( 'ext.quicksurveys.lib' ).showSurvey( 'foo' );
The ext.quicksurveys.lib module loads the configuration for all enabled surveys. Further, the ext.quicksurveys.lib module also calls showSurvey() unconditionally in order to show a survey to the user on page load. Unfortunately, this means that an unrelated survey may be shown when using the showSurvey() as above.
Solution
Move the unconditional showSurvey() call into the ext.quicksurveys.init.
The ext.quicksurveys.init module is one that has no assets and no dependencies when no surveys are configured and depends on the ext.quicksurveys.lib module when one or more surveys are configured. We could move the showSurvey() call to this module, i.e.
<?php namespace QuickSurveys\ResourceLoader; use MediaWiki\MediaWikiServices; use ResourceLoaderContext; class InitModule extends \ResourceLoaderFileModule { public function getScript( ResourceLoaderContext $context ) { if ( !$this->hasEnabledSurveys() ) { return ''; } return <<<JS var FORCED_SURVEY = mw.util.getParamValue( 'quicksurvey' ); require( 'ext.quicksurveys.lib' ).showSurvey( FORCED_SURVEY ); JS; } public function getDependencies( ResourceLoaderContext $context = null ) { /* ... */ } private function hasEnabledSurveys(): bool { /* ... */ } }