Skip to content

Clean up middleware signature#5504

Merged
compulim merged 26 commits intomicrosoft:mainfrom
compulim:feat-cleanup-decorator
Jun 25, 2025
Merged

Clean up middleware signature#5504
compulim merged 26 commits intomicrosoft:mainfrom
compulim:feat-cleanup-decorator

Conversation

@compulim
Copy link
Copy Markdown
Contributor

@compulim compulim commented Jun 24, 2025

Changelog Entry

Breaking changes

  • The following middleware should be created using their respective factory functions:
    • activityBorderDecoratorMiddleware, related to PR #5504
    • activityGroupingDecoratorMiddleware, related to PR #5504
    • sendBoxMiddleware, related to PR #5504
    • sendBoxToolbarMiddleware, related to PR #5504

Added

  • Added sendBoxMiddleware and sendBoxToolbarMiddleware, by @compulim, in PR #5120 and #5504
    • Instead of passing barebone middleware, use the createSendBoxMiddleware and createSendBoxToolbarMiddleware correspondingly, related to PR #5504

Description

Clean up middleware signature to prepare for poly-middleware.

Eventually, we will unite all middleware signature to the following format.

const someMiddleware: Middleware<Request, Props> = 
  (init: string) => 
    (next: Enhancer<Request>) => 
      (request: Request) =>
        next(request) satisfies ComponentType<Props>;

Design

Introduction of createXXXMiddleware

Narrowing and guarding function overloading is still weak in TypeScript. Until they improve it, we need a "wrapping function" to make middleware typed properly.

We cannot do use first argument to differentiate the type of return value.

interface SomeFunction {
  (type: 'n'): number;
  (type: 's'): string;
}

We will also leverage the createXXXMiddleware for backward/forward compatibility.

Specific Changes

  • Cleaned up decorator middleware typing
    • Removed unnecessary typing and their exports
    • init will always be a string, only Request and Props are customizable
    • Added new createActivityBorderMiddleware(), createActivityGroupingMiddleware(), createSendBoxMiddleware() and createSendBoxToolbarMiddleware() helper functions to wrap their decorator middleware correspondingly
  • Updated templateMiddleware
    • New typing helper Infer*<typeof template> to infer from template['~types']
  • I have added tests and executed them locally
  • I have updated CHANGELOG.md
  • I have updated documentation

Review Checklist

This section is for contributors to review your work.

  • Accessibility reviewed (tab order, content readability, alt text, color contrast)
  • Browser and platform compatibilities reviewed
  • CSS styles reviewed (minimal rules, no z-index)
  • Documents reviewed (docs, samples, live demo)
  • Internationalization reviewed (strings, unit formatting)
  • package.json and package-lock.json reviewed
  • Security reviewed (no data URIs, check for nonce leak)
  • Tests reviewed (coverage, legitimacy)

@compulim compulim changed the title [WIP] Clean up middleware signature Clean up middleware signature Jun 25, 2025
@compulim compulim marked this pull request as ready for review June 25, 2025 11:28
@compulim compulim requested a review from beyackle2 as a code owner June 25, 2025 11:28
@compulim compulim merged commit c59e6ed into microsoft:main Jun 25, 2025
25 checks passed
@compulim compulim deleted the feat-cleanup-decorator branch June 25, 2025 21:41
@OEvgeny OEvgeny mentioned this pull request Jul 9, 2025
11 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants