Skip to content

🙏 SPFx v1.13 beta20 web part template feedback - please don't bloat the default class #PleaseChange #7308

@andrewconnell

Description

@andrewconnell

Target SharePoint environment

SharePoint Online

What SharePoint development model, framework, SDK or API is this about?

💥 SharePoint Framework

Developer environment

macOS

What browser(s) / client(s) have you tested

  • 💥 Internet Explorer
  • 💥 Microsoft Edge
  • 💥 Google Chrome
  • 💥 FireFox
  • 💥 Safari
  • mobile (iOS/iPadOS)
  • mobile (Android)
  • not applicable
  • other (enter in the "Additional environment details" area below)

Additional environment details

  • browser version (n/a)
  • SPFx 1.13.0 beta 20
  • Node.js 14.17.3

Describe the bug / error

TLDR

The new web part template introduced within the most recent beta (#20) for the upcoming 1.13.0 SPFx release is loaded with additional code that's not necessary. Please move this to a new ThemedBaseClientSideWebPart class & inherit from it.

More

The new base web part class is now loaded with theming bloat in the simplest "hello world" web part using no web framework. Specifically:

  • 5 new private members to support MS Teams themes
  • a 25-line onInit() method to support MS Teams themes
  • 6 new private methods to support MS Teams themes

IMHO, this is bad for multiple reasons:

  1. if you aren't building for MS Teams, the majority of this code is moot
  2. the first-run experience for a new developer is worse than before because they now have 220 LOC they have to figure out "where do I put my stuff? what can I remove? can I modify any of this?"
  3. if there's one typo in any of this boilerplate code, SPFx v1.13.1's release notes will be filled with "find this line & change it to the following..."
  4. if you're building a solution that will never be used within MS Teams, most of this code is irrelevant
  5. if you're building a solution that WILL be used in MS Teams, there's very little reason to change any of this code

Steps to reproduce

  1. install latest SPFx generator beta: npm install @microsoft/generator-sharepoint@next -g
  2. create a new project, accept all default values when prompted by the yeoman generator
  3. open the project in a text editor such as VS Code
  4. look at the base web part class... all 220 lines of it :(

Expected behavior

Default projects should not be filled with boilerplate code that's not intended to be modified. That code should be in base classes.

Proposed solution

Why not push ALL this stuff in the three bullet points above into a new class and inherit from it? For instance:

  1. create a new base class and include it within the @microsoft/sp-webpart-base:

    export class ThemedBaseClientSideWebPart<TProperties> extends BaseClientSideWebPart<TProperties> {}
  2. 100% of the three bullet items from above into this new class (including the private members & onInit()), along with the import dependencies & remove all that from the new web part class template

  3. change the web part class template to create a web part that looks like this:

    export default class HelloWorldWebPart extends ThemedBaseClientSideWebPart<IHelloWorldWebPartProps> {}
  4. bask in your coding glory

Metadata

Metadata

Assignees

No one assigned

    Labels

    Needs: Triage 🔍Awaiting categorization and initial review.area:spfxCategory: SharePoint Framework (not extensions related)

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions