Files
gyf9835andgaoyifeng 04a5903596 fix(web): repair tabby-web-container boot (compiler order, pluginModules, pluginName tagging) (#11915)
* fix(web): register @angular/compiler before other @angular packages

tabby-web-container's preload registered @angular/compiler after
@angular/cdk and @angular/cdk/clipboard. Because the module argument to
Tabby.registerModule is evaluated eagerly, requiring @angular/cdk/clipboard
pulls in @angular/common before the compiler has run.

@angular/common and @angular/cdk are shipped as partially compiled
(\u0275\u0275ngDeclare*) fesm bundles and this webpack config does not run the
Angular Linker over them, so they rely on the JIT fallback, which reads
ng.\u0275compilerFacade - published by @angular/compiler when it is evaluated:

  Error: The injectable 'PlatformLocation' needs to be compiled using the
  JIT compiler, but '@angular/compiler' is not available.

This aborts the whole bundle, leaving window.bootstrapTabby undefined, so
every plugin then fails with 'Attempted to require @angular/common' and the
web UI stays blank. Affects tabby-web-container 1.0.197-nightly.1 and
1.0.231-nightly.0; 1.0.189-nightly.2 (Angular 12) is unaffected.

Registering @angular/compiler first publishes the facade before anything
else is required.

* fix(web): expose window.pluginModules to the plugin-provided services

tabby-core's ConfigService.enabledServices() iterates over
window['pluginModules'] to collect providers contributed by plugins - this
is what ThemesService uses to apply the current theme. entry.ts only kept
pluginModules as a local variable, so the global was never set and
bootstrapping threw:

  TypeError: window.pluginModules is not iterable
    at ConfigService.enabledServices (tabby-core/dist/index.js)
    at ThemesService.applyThemeVariables

Publish the array on window before building the root module.

* fix(web): tag plugin modules with their name

loadPlugins()/loadPlugin() returned the module from webRequire() as-is, but
bootstrap() reads `packageModule.pluginName` and tabby-core keys
ConfigService.servicesCache by that field:

  this.servicesCache[module.pluginName] = module.\u0275inj.providers...

Since pluginName was never set, every plugin landed on the single key
"undefined" and each one overwrote the previous, leaving enabledServices()
with only the last loaded plugin's providers. Symptomatically the SSH
connection type disappeared from the "new connection" menu once tabby-telnet
started loading after tabby-ssh.

It stayed hidden because enabledServices() returns true for services it does
not recognise, so only plugins that consult the cache for a decision broke.

Tag the module in both entry points.

---------

Co-authored-by: gaoyifeng <work@gyf.name>
2026-11-24 00:21:28 +01:00

62 lines
2.1 KiB
TypeScript

import './polyfills'
import 'zone.js'
import 'core-js/proposals/reflect-metadata'
import 'core-js/features/array/flat'
import 'rxjs'
import '../app/src/global.scss'
import '../app/src/toastr.scss'
import { enableProdMode, NgModuleRef, ApplicationRef } from '@angular/core'
import { enableDebugTools } from '@angular/platform-browser'
import { platformBrowserDynamic } from '@angular/platform-browser-dynamic'
import { getRootModule } from '../app/src/app.module'
import { BootstrapData, BOOTSTRAP_DATA } from '../tabby-core/src/api/mainProcess'
interface BootstrapOptions {
packageModules: any[]
bootstrapData: BootstrapData
debugMode: boolean
connector: any
}
window['bootstrapTabby'] = async function bootstrap (options: BootstrapOptions): Promise<NgModuleRef<any>> {
window.parent.postMessage('request-connector', '*')
const pluginModules = []
for (const packageModule of options.packageModules) {
if (!packageModule.default) {
continue
}
const pluginModule = packageModule.default.forRoot ? packageModule.default.forRoot() : packageModule.default
pluginModule.pluginName = packageModule.pluginName
pluginModule.bootstrap = packageModule.bootstrap
pluginModules.push(pluginModule)
}
if (!options.debugMode) {
enableProdMode()
}
// config.service.ts iterates window.pluginModules to discover the providers
// contributed by every plugin (used by ThemesService and friends), so it has
// to be exposed globally, not just passed to getRootModule().
window['pluginModules'] = pluginModules
const module = getRootModule(pluginModules)
window['rootModule'] = module
const moduleRef = await platformBrowserDynamic([
{ provide: BOOTSTRAP_DATA, useValue: options.bootstrapData },
{ provide: 'WEB_CONNECTOR', useValue: options.connector },
]).bootstrapModule(module)
if (options.debugMode) {
const applicationRef = moduleRef.injector.get(ApplicationRef)
const componentRef = applicationRef.components[0]
enableDebugTools(componentRef)
}
return moduleRef
}