Skip to content

Proposal: modernize @comark/angular (signal inputs, inject()) #296

Open

Description

@schplitt

The Angular package currently uses @Input() decorators and constructor injection everywhere. I would like to do a modernization pass: signal inputs via input(), inject() instead of constructors, and computed() where it makes sense.

There is one catch: signal inputs are stable since Angular 19, and the package currently allows >=17. So this would raise the minimum supported Angular version. That is your call as maintainers, which is why I'm asking here first instead of just sending a PR.

For consumers nothing changes. Props on custom components are already set via setInput(), and that works the same with signal inputs.

If you're open to this, let me know which Angular version you're comfortable with as the new minimum and I'll prepare the PR. I would keep it separate from the bug fixes (#294, #295) so those can land independently.

Activity

  1. atinux commented on Jul 28, 2026

    @atinux
    Contributor

    What do you think @arashsheyda ?

  2. arashsheyda commented on Jul 31, 2026

    @arashsheyda
    Collaborator

    I think it would be a good idea to change the minimum to v19 🚀

  3. atinux commented on Aug 12, 2026

    @atinux
    Contributor

    Could we close this issue too as #346 is merged?

  4. schplitt commented on Aug 12, 2026

    @schplitt
    Author

    Could we close this issue too as #346 is merged?

    I wouldn't say so to be honest.
    A lot of modern angular features are not used currently.

    I would be very in favor of it (though this would raise the minimal version for Angular to 19).

    I'm unsure if you would be in favor of that or not.
    If so let me know and I will look into it myself.

  5. arashsheyda commented on Aug 13, 2026

    @arashsheyda
    Collaborator

    @schplitt do you want to open a PR so we can review?

  6. adrian-ub commented on Sep 17, 2026

    @adrian-ub
    Contributor

    Hey there! I started working on this

    PR: #446 — migrate to signal inputs and ng-packagr

    It covers everything proposed here:

    • Signal inputs — @Input() → input() across Markdown, MarkdownDocument, MarkdownNode, Binding, Math and Mermaid components
    • inject() instead of constructor injection, plus computed() where it made sense
    • Build migration to ng-packagr — the hand-rolled ngc pipeline is gone; component plugins are now secondary entry points (plugins/binding, plugins/math, plugins/mermaid)
    • Minimum Angular raised to v19, as agreed in this thread (peer deps now >=19 <23)

    For consumers nothing changes: props on custom components are still set via setInput().

    Happy to adjust anything — would love a review!

    cc @arashsheyda @farnabaz @atinux @schplitt

  7. adrian-ub commented on Sep 18, 2026

    @adrian-ub
    Contributor

    Follow-up on defineMarkdownComponent / defineMarkdownDocumentComponent, before this lands in #446. This one part needs your input because it is a breaking change, and the "for consumers nothing changes" note above does not cover it.

    The current helpers return a component class created inside a factory (a @Component subclass built by the function). That pattern is not AOT-compatible: putting the factory result in another component's imports: triggers ngtsc error -991010 ("value could not be determined statically"). It works in dev (JIT) but breaks production builds, so it can't be the recommended API.

    Proposed change: make the helpers return a config Provider, and read that config in the static Markdown / MarkdownDocument components via an InjectionToken:

    @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" />
      `,
    })

    All the existing per-instance inputs (value, options, plugins, components, unwrap, summary, streaming, caret, data) keep working as before. Instance inputs win over the config, so the provider is purely the pre-configured baseline.

    Sketch of how the components read the provider:

    // config.ts
    export const MARKDOWN_CONFIG = new InjectionToken<MarkdownConfig>('comark.MARKDOWN_CONFIG')
    
    // markdown.component.ts (simplified)
    private readonly config = inject(MARKDOWN_CONFIG, { optional: true })
    
    protected getParserOptions(): ParserOptions {
      return {
        ...(this.config?.options ?? {}),
        ...this.options(),
        plugins: this.effectivePlugins(),  // config plugins first, instance plugins after, deduped by name
      }
    }
    
    protected readonly mergedComponents = computed(() => ({
      ...(this.config?.components ?? {}),
      ...this.components(),
    }))
    
    get hostClass(): string {
      return this.config?.class ?? ''
    }

    There is a branch with the complete implementation if you'd like to try it directly:

    https://github.com/adrian-ub/comarkdown-comark/tree/feat/angular-provider-config

    The branch also removes the need for consumers to explicitly import @angular/compiler.

    Additionally, while working on this, I cleaned up the rendered DOM structure. Instead of producing several internal wrapper elements such as:

    <comark-markdown>
      <comark-markdown-document>
        <div class="comark-content">
          <comark-markdown-node>
            <h1 id="comark-syntax-showcase">...</h1>
          </comark-markdown-node>
        </div>
      </comark-markdown-document>
    </comark-markdown>

    the rendered output can now be reduced to:

    <comark-markdown
      style="display: block;"
      class="comark-content dark:prose-invert prose"
    >
      <h1 id="comark-syntax-showcase">...</h1>
    </comark-markdown>

    This removes the extra comark-markdown-document / comark-markdown-node wrappers from the final DOM while preserving the rendered content and Angular component behavior. The attached output shows the before/after DOM difference across the syntax showcase.
    The implementation is ready and verified locally (60 tests passing, clean AOT build of the example app). I haven't committed it to #446 yet because I'd like to confirm the API direction first.

    Would the maintainers be OK with this direction (the helper returns a Provider instead of Type<Markdown>), or would you prefer a different shape? Happy to adjust.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions