Skip to content

Commit

Permalink
Merge pull request #580 from Siphalor/hotfix/#579-ng-platforms
Browse files Browse the repository at this point in the history
Fix #579 (piral-ng destroying all modules instead of only the intended one)
  • Loading branch information
FlorianRappl authored Feb 1, 2023
2 parents 143d72e + d544cf6 commit e23df08
Showing 1 changed file with 21 additions and 3 deletions.
24 changes: 21 additions & 3 deletions src/converters/piral-ng/src/startup.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,18 @@
import type { ComponentContext } from 'piral-core';
import type { NgOptions } from './types';
import { enableProdMode, NgModuleRef, NgZone, PlatformRef } from '@angular/core';
import {
createPlatformFactory,
enableProdMode,
NgModuleRef,
NgZone,
PlatformRef,
ɵALLOW_MULTIPLE_PLATFORMS as ALLOW_MULTIPLE_PLATFORMS,
} from '@angular/core';
import { APP_BASE_HREF } from '@angular/common';
import { platformBrowserDynamic } from '@angular/platform-browser-dynamic';
import {
ɵplatformCoreDynamic as platformCoreDynamic,
ɵINTERNAL_BROWSER_DYNAMIC_PLATFORM_PROVIDERS as INTERNAL_BROWSER_DYNAMIC_PLATFORM_PROVIDERS,
} from '@angular/platform-browser-dynamic';
import { getId, getNgVersion } from './utils';

function getVersionHandler(versions: Record<string, () => void>) {
Expand All @@ -11,11 +21,19 @@ function getVersionHandler(versions: Record<string, () => void>) {
return versions[version];
}

// Equivalent to platformBrowserDynamic, but with support for multiple platforms
const customPlatformDynamicFactory = createPlatformFactory(platformCoreDynamic, 'piralDynamic', [
...INTERNAL_BROWSER_DYNAMIC_PLATFORM_PROVIDERS,
{
provide: ALLOW_MULTIPLE_PLATFORMS,
useValue: true,
},
]);
const runningModules: Array<[any, NgModuleInt, PlatformRef]> = [];

function startNew(BootstrapModule: any, context: ComponentContext, ngOptions?: NgOptions) {
const path = context.publicPath || '/';
const platform = platformBrowserDynamic([
const platform = customPlatformDynamicFactory([
{ provide: 'Context', useValue: context },
{ provide: APP_BASE_HREF, useValue: path },
]);
Expand Down

0 comments on commit e23df08

Please sign in to comment.