Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Upgrade angular hybrid from 7.0.0 to latest (10) Angular states no longer registering #437

Closed
SamanthaAdrichem opened this issue Jun 8, 2020 · 10 comments
Labels

Comments

@SamanthaAdrichem
Copy link

SamanthaAdrichem commented Jun 8, 2020

We've been using angular-hybrid from a while and today we've upgraded to Angular 9.0.7 (wanted to go to 9.1.9, but there are issues with the compiler on windows).

We've always written our states in separate module files with each page.

const states: NgHybridStateDeclaration[] = [
	{
		name: 'publisher-statistics-hour',
		url: '/publisher/statistics/hour',
		component: HourComponent
	},
	{
		name: 'publisher-statistics-day',
		url: '/publisher/statistics/day',
		component: DayComponent
	}
];

@NgModule({
	imports: [
		UIRouterUpgradeModule.forChild({states: states})
	],
	exports: [
		UIRouterUpgradeModule
	],
})
export class StatisticsRoutingModule {}

Now since upgrading uirouter, which was at 7.0.0 to the following

		"@uirouter/angular": "6.0.2",
		"@uirouter/angular-hybrid": "10.0.1",
		"@uirouter/angularjs": "1.0.26",
		"@uirouter/core": "6.0.5",
		"@uirouter/rx": "0.6.5",

our bootstrap is still as such

// If ready
if (/comp|inter|loaded/.test(document.readyState)) {
	bootstrap();
} else {
	document.addEventListener('DOMContentLoaded', bootstrap);
}

function bootstrap(): void {
	if (true === environment.production) {
		enableProdMode();
	}

	platformBrowserDynamic().bootstrapModule(
		AppModule,
		[{
			defaultEncapsulation: ViewEncapsulation.None
		}]
	).then((platformRef: NgModuleRef<AppModule>) => {
		// Initialize the Angular Module
		// get() the UIRouter instance from DI to initialize the router
		const urlService: UrlService = platformRef.injector.get(UIRouter).urlService;

		// Instruct UIRouter to listen to URL changes
		platformRef.injector.get<NgZone>(NgZone).run(() => {
			console.log('listening');
			urlService.listen();
			urlService.sync();
		});
	});
}

The routes inside angular are no longer being loaded. All AngularJS routes still work and exist.
Can't seem to find a change listed to explain this.

Anyone got any clue what changed?

@SamanthaAdrichem
Copy link
Author

SamanthaAdrichem commented Jun 8, 2020

If I add console.log's the router modules are being loaded before the sync,
if i add a breakpoint to the sync and check the URL service, the routes are not in the states param
urlService.router.stateRegistry.states

if i add the route directly inside the app.module, it still doesn't exist

@SamanthaAdrichem
Copy link
Author

Trying to debug it.

Seems like when it hits t his piece of code, which it only hits once the modules is an empty array

// Register the ng1 DI '$uiRouter' object as an ng2 Provider.
export function uiRouterUpgradeFactory(router: UIRouter, injector: Injector) {
  const modules: StatesModule[] = injector.get<StatesModule[]>(UIROUTER_MODULE_TOKEN, []);
  modules.forEach(module => applyModuleConfig(router, injector, module));
  return router;
}

Same for this piece of code that also only passes by once, states is undefined resulting in an empty [] due to the || statement

export function applyModuleConfig(uiRouter: UIRouter, injector: Injector, module: StatesModule = {}): StateObject[] {
  if (isFunction(module.config)) {
    module.config(uiRouter, injector, module);
  }

  const states = module.states || [];
  return states.map((state) => uiRouter.stateRegistry.register(state));
}

@SamanthaAdrichem
Copy link
Author

Ok it seems that in the function above, the UIROUTER_MODULE_TOKEN is undefined. (apperently we're loading the fesm5 version)

@SamanthaAdrichem
Copy link
Author

SamanthaAdrichem commented Jun 8, 2020

Ok seen that the UIROUTER_MODULE_TOKEN was set to a separate file in @uirouter/angular 6.0.2 i've downgraded to 6.0.1 which seems to fix it. It's broken for hybrid in 6.0.2. though!

@ckniffen
Copy link

ckniffen commented Jun 8, 2020

@SamanthaAdrichem Looked into this further as we have the same issue.

It wasn't the moving to a separate file that broke it but that it is no longer exported from index.ts

@SamanthaAdrichem
Copy link
Author

I figured as much, but during local debugging inside node_modules, including it didn't fix it so I wasn't sure.

@christopherthielen
Copy link
Member

Did you ever resolve this problem and were you able to upgrade? @SamanthaAdrichem

@christopherthielen
Copy link
Member

ui-router/angular#810

@SamanthaAdrichem
Copy link
Author

Nope, never had the time, otherwise i would’ve made a PR. I think your new PR fixes it.

@stale
Copy link

stale bot commented Nov 12, 2022

This issue has been automatically marked as stale because it has not had
recent activity. It will be closed if no further activity occurs.
This does not mean that the issue is invalid. Valid issues
may be reopened.
Thank you for your contributions.

@stale stale bot added the stale label Nov 12, 2022
@stale stale bot closed this as completed Jan 7, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants