feat(angular): provide AOT-compatible provider-based config for defineMarkdownComponent (NG1010)
Summary
defineMarkdownComponent(...) (and likely defineMarkdownDocumentComponent(...)) returns a component class created inside a runtime factory. In Angular's AOT/static compilation model this value cannot be statically determined, so using the factory result in a standalone component's imports fails with NG1010 (ngtsc -991010). The pattern works in JIT/dev but breaks production/AOT builds, so it cannot be the recommended API for configuring markdown rendering.
This follows up on the discussion in #296 (comment https://github.com/comarkdown/comark/issues/296#issuecomment-6979194088): the provider-based API question was explicitly split out of #446 and maintainers asked to open a new issue or PR to pursue it.
Context / prior discussion
- #296 — "Proposal: modernize
@comark/angular(signal inputs,inject())" (closed, delivered via #446 except this point) - @adrian-ub proposal: https://github.com/comarkdown/comark/issues/296#issuecomment-5722880758 (describes the AOT incompatibility, sketches a Provider/InjectionToken-based config, and links a reference implementation: https://github.com/adrian-ub/comarkdown-comark/tree/feat/angular-provider-config)
- Maintainer request to track separately: https://github.com/comarkdown/comark/issues/296#issuecomment-6979194088
Environment / reproduction
- Angular: 22.2.x (
@angular/build:application/ application builder, dev server & build) @comark/angular: 0.9.1 (previewhttps://pkg.pr.new/@comark/angular@446)comark-content: 0.6.0- Package manager / command: pnpm,
pnpm ng serve(also fails withng build)
// app.ts
import { Component } from '@angular/core';
import { defineMarkdownComponent } from '@comark/angular';
export const DocsMarkdown = defineMarkdownComponent({
plugins: [],
components: {},
class: 'prose dark:prose-invert',
});
@Component({
selector: 'app-root',
standalone: true,
imports: [DocsMarkdown],
templateUrl: './app.html',
})
export class App {}
Actual result
Build/serve fails during Angular compilation:
NG1010: 'imports' must be an array of components, directives, pipes, or NgModules.
Value could not be determined statically.
'DocsMarkdown' cannot be statically determined because it is produced by the external
call `defineMarkdownComponent(...)` (external declaration / factory result).
Expected result
Markdown rendering options (plugins, component mappings, wrapper class, transforms, etc.) can be configured in a way that is statically analyzable and AOT-compatible with standalone imports, without generating a component class at runtime.
Motivation
- AOT/production compatibility: the factory-returned class breaks the default Angular build pipeline (NG1010/-991010), even if it may appear to work in JIT/dev.
- Idiomatic Angular configuration: options like
plugins/components/classare configuration concerns and fit Angular DI (similar toprovideRouter,provideHttpClient, etc.) better than manufacturing a component type per config. - Stable, analyzable components: a statically-declared
Markdown/MarkdownDocumentcomponent can be imported safely while configuration is provided via DI and scoped (app/route/component) as needed.
Proposed solution
Adopt the direction sketched by @adrian-ub in #296: make defineMarkdownComponent / defineMarkdownDocumentComponent return a config Provider (e.g. backed by an InjectionToken such as MARKDOWN_CONFIG) consumed by the static Markdown / MarkdownDocument components.
Illustrative usage (from the prior discussion):
@Component({
standalone: true,
imports: [Markdown], // static, AOT-safe
providers: [defineMarkdownComponent({ // same helper, same options
plugins: [math()],
components: { Math },
class: 'prose dark:prose-invert',
})],
template: `
<comark-markdown [value]="content" [streaming]="true" [caret]="true" />
`,
})
export class App {}
- All existing per-instance inputs (
value,options,plugins,components,unwrap,summary,streaming,caret,data) keep working. - Instance inputs win over provider config (provider as pre-configured baseline); config plugins/components merge/dedupe as appropriate.
- Reference implementation for evaluation: https://github.com/adrian-ub/comarkdown-comark/tree/feat/angular-provider-config
Additional notes
- This is reported as an enhancement/API direction because the fix is a (breaking) API shape change, but it addresses a concrete AOT/build failure (NG1010) in current usage.
- Reproduced in a real project setup using the current preview package; happy to provide/adjust a minimal public reproduction if helpful.