SlideShare a Scribd company logo
Pitfalls when developing with the
SharePoint Framework (SPFx)
Chris O’Brien (MVP)
Independent/Content and Code, UK
Add
Speaker
Photo here
Notes on this presentation
If you have previously seen this presentation/slide deck
before, note the following updates:
Content Slides
Pitfalls around Office UI Fabric 27-30
Pitfalls around calling the Microsoft
Graph or custom APIs secured with Azure
Active Directory
31-35
Use of SPFx component bundles 40-42
Chris OBrien - Pitfalls when developing with the SharePoint Framework (SPFx)
Fundamentals – how it all works
Packages installed/updated using npm
• .NET analogy = NuGet
Dependent JS libraries stored in node_modules
• .NET analogy = the BIN directory
• Gets bundled/deployed with your app
Package.json records your top-level dependencies
• .NET analogy = packages.config
• Allows other devs to build app from source control
• N.B. Each dependency may have IT’S OWN dependencies and package.json
COB App
- node_modules
- jQuery
- node_modules
- cache-swap
- node_modules
- React
- node_modules
……
Simplified node_modules hierarchy
Fundamentals - how to add a library
Use npm install command e.g:
npm install jquery
Installs library to your app (in node_modules)
Important parameter:
--save OR --save-exact
Usually add TypeScript typings (for auto-complete)
npm install @types/jquery -–save
Understanding package.json
dependencies node
• Lists all 3rd party libraries needed to
run
devDependencies node
• Lists all 3rd party libraries needed to
develop/build
Semantic versioning (semver)
Example Known as Meaning
^1.2.1 Caret dependency Greater than or equal to 1.2.1, but less than 2.0.0
~1.2.1 Tilde dependency Greater than or equal to 1.2.1, but less than 1.3.0
1.2.1 Exact dependency 1.2.1 only
Fundamentals
3 part version number – e.g. 1.0.0
Major.Minor.Patch
Major = breaking change/substantial differences
Minor = non-breaking e.g. new methods
Patch = no interface changes e.g. optimisations,
documentation
Versioning/dependency pitfalls
Using caret
dependencies (the
default)
Not specifying –
save on npm install
Dev:
Not locking
dependencies
down
Shipping:
Will change in
npm 5!
--save
(until npm 5)
Dependencies and shipping
The problem – “dependency float”
• Your app has many JS dependencies (the node_modules tree)
• node_modules should not be checked-in
• Different version somewhere in tree -> Broken app
The solution – npm shrinkwrap
• Generates npm-shrinkwrap.json file
Critical to getting a “100% reproducible build”
• Locks down dependencies – for entire node_modules tree
npm shrinkwrap
Tip - check-in npm-shrinkwrap.json
for each shipped release
• Allows exact build to be recreated
• Allows other devs to build exact app from
source control
Better than save-exact – deals with
full dependency tree
• save-exact only deals with top-level
dependencies
Chris OBrien - Pitfalls when developing with the SharePoint Framework (SPFx)
Remember the rule:
= OK
^ = Not OK
Recommendations – versioning etc.
Pitfall How avoided More reading
Avoid dependency issues
in dev
Ensure devs *save* packages properly – use npm
install --save/--save-exact.
Consider custom .npmrc file across team
http://cob-
sp.com/2fOtApJ
Avoid dependency issues
when shipping
Use npm shrinkwrap for each release https://docs.npmjs.
com/cli/shrinkwrap
Chris OBrien - Pitfalls when developing with the SharePoint Framework (SPFx)
Code re-use pitfall
Copy/pasting JS code into each app,
because not clear how to re-use properly
Re-using existing JS code
Create a module for your code
• Expose each method with exports statement:
module.exports = {
CheckRealValue: COB.CORE.Utilities.CheckRealValue,
StringIsEmpty: COB.CORE.Utilities.StringIsEmpty
}
Create package.json file
• Specify entry point (file)
Re-using existing JS code
Access module with ‘require’
• var cobUtil = require('cob-utility')
• cobUtil.StringIsEmpty("foo");
Chris OBrien - Pitfalls when developing with the SharePoint Framework (SPFx)
So, now you have a module.
How to include/reference that?
Some popular options
Use npm LOCAL packages
• Install from file path (COPY) or use NPM LINK
Use node_modules higher up filesystem
• Take advantage of “recurse upwards” approach of npm- See http://cob-
sp.com/2eXDJOI
Use private package hosting
• npm private packages - $7 pm/user
• VSTO private hosting - $4 pm/user
Also consider:
https://www.visualstudio.co
m/en-
us/docs/package/install
Recommendations – code re-use
Pitfall How More reading
Copy/pasting JS code into
each project
Create modules for existing code
Consider module strategy:
• npm install [filepath]
• npm link (for “parallel dev” of client and utility
code)
• Use of npm private packages etc.
http://nicksellen.co.
uk/2015/04/17/ho
w-to-manage-
private-npm-
modules.html
http://stackoverflo
w.com/questions/2
1233108/cross-
project-references-
between-two-
projects
Chris OBrien - Pitfalls when developing with the SharePoint Framework (SPFx)
SPFX coding pitfalls
Dealing with async
code/ promises
Calling the
Microsoft Graph
(permutations)
Calling secure APIs
(AAD)Office UI Fabric
Adding a library
TypeScript issues
Pitfall – Office UI Fabric issues
Problem:
You want to use Fabric but are confused..
Office UI Fabric
• Office UI Fabric Core a.k.a. Fabric Core - this is a set of
core styles, typography, a responsive grid, animations,
icons, and other fundamental building blocks of the
overall design language.
• Office UI Fabric React a.k.a. Fabric React - this package
contains a set of React components built on top of the
Fabric design language.
Pitfall – Office UI Fabric issues
Problem:
You want to use Fabric but are confused..
Solution:
• To use Fabric Core easily, use SPFx v1.3.4
or later (
• Using React? Can use Fabric React
components – use individual static links
(for bundle size)
Key npm packages:
• office-ui-fabric-
react
• @microsoft/sp-
office-ui-fabric-
core (new)
Correct use of Fabric React (bundling
approach)
WARNING – React styles are bundled with EACH web part in this
approach. Mitigate with SPFx component bundles if you need to (e.g.
expecting many of your web parts on page).
See http://cob-sp.com/2hPVmUc
Pitfall – calling the Graph/custom APIs
Problem:
You need to call the Graph or a custom API
from SPFx (i.e. AAD-secured)
Solution:
• Understand today’s options:
• GraphHttpClient (limited scenarios!)
• AAD app + adal.js
• AAD app + SPO auth cookie/IFrame approach
• Understand a future option:
• AAD app + tell SPFx to trust it
Graph/custom API permutations
- GraphHttpClient
- or more likely, use of adal.js
Calling the Graph from
client-side
- adal.js
- SPO auth cookie/IFrame
Calling custom API (AAD)
from client-side
•- adal.js from client (SPO auth cookie approach gives token
which cannot be used with Graph)
- adal.NET within custom API
OR
- New Azure Functions bindings (preview – can’t get to work!)
- Use of both “on behalf of user” and “app-only”
Calling custom API
(AAD) from client-side
which calls the Graph
Reference:
Connect to API
secured with AAD -
http://cob-
sp.com/SPFx-AAD
Cheat sheet - custom APIs/Azure Functions
with AAD
ADAL.js
• CORS – define rule for each
calling page
• Code - Ensure asking for
token for your resource
(AAD client ID)
SPO auth cookie approach
• Empty CORS rules
• Code:
• Pass “credentials” :
“include” header, and sure
API/Function can receive..
• IFrame onto Function URL
Reference:
Connect to API
secured with AAD -
http://cob-
sp.com/SPFx-AAD
CONSIDER:
• Each web part/extension on
page must sign-in
• AAD reply URL needed for
each page with WP (max 10!)
CONSIDER:
• Sign-in applies to entire
page/session
• Cannot access user
identity (app-only)
Future option – Graph/customAPIs
Graph - Specify additional permission
scopes for GraphHttpClient
e.g. I’m OK with all SPFx web parts having access to
more than Groups and Reports
Your APIs/Azure Functions
Specify additional custom APIs for same token
Benefit – no need for sign-in button in your
WP/extension
Dev preview late 2017?
{
"WebApiPermissionRequest": {
"ResourceId": “GUID goes here",
"Scope": “GUID goes here",
}
"WebApiPermissionRequest": {
"ResourceId": “GUID goes here",
"Scope": “GUID goes here",
}
"WebApiPermissionRequest": {
"ResourceId": “GUID goes here",
"Scope": “GUID goes here",
}
Recommendations – coding
Pitfall How avoided More reading
Office UI Fabric
issues
Get familiar with:
• Fabric Core vs. Fabric React components
• SPFx 1.3.4/sp-office-ui-fabric-core package
• Using mixins in your SCSS
http://cob-sp.com/SPFx-
OUIF
Graph/custom API
issues
Get familiar with:
• Register AAD apps + adal.js
• SPO auth cookie approach
• Future SPFx option
http://cob-sp.com/SPFx-AAD
Async code issues Get familiar with:
• Promises
http://cob-sp.com/SPFX-
Promises
Security issues Avoid SPFX if sensitive data sent to client (page
or JS) - use Add-in parts/IFrames if needed
http://cob-sp.com/2ez9JNX
Chris OBrien - Pitfalls when developing with the SharePoint Framework (SPFx)
Pitfalls - deployment
Accidentally
bundling external
libraries/frameworks
Accidentally shipping
a debug build
Losing track of
remote JS code
Bundling considerations
Librariesare includedin your bundle BY DEFAULT
Update config.json if (e.g.) jQuery should be referenced from CDN
One bundleper web part BY DEFAULT - across your site
10 web parts = 10 different copies of jQuery being downloaded
GUID in bundleURL is regeneratedon each build
This is the versioning/cache-busting mechanism
TIP – delete unused JS files from CDN to keep things tidy
Chris OBrien - Pitfalls when developing with the SharePoint Framework (SPFx)
Bundling – rule #1
“Externalise” where possible (CDN):
Bundling – rule #2
Ensure any libs you ARE bundling are consolidated (with
SPFx component bundles):
WP1 WP2
cob-bothWebParts.js
Recommendations – deployment
Pitfall How avoided More reading
Accidental
bundling
Ensure libs loaded externally where possible
Update “externals” section of config.json
Waldek - http://cob-
sp.com/2frVMR3
Duplication of code
in bundle
Use SPFx component bundles Elio - http://cob-
sp.com/SPFx-
CompBundle
Losing track of
remote JS code
• Proactively track CDN locations (e.g. Excel?)
• Use SPCAF to help identify
www.spcaf.com
Key take-aways
It’s a new world, with different pitfalls!
Recommendations:
Get familiar with NPM especially
Plan for code re-use (e.g. modules) if appropriate
Practice “production” deployments
Dependencies/versioning e.g. dependency float
Coding e.g. OUIF, calling the Graph or custom APIs
Deployment e.g. accidental bundling, duplication in bundle
Thank you!! 
Any questions?
www.sharepointnutsandbolts.com
Bundling – how it goes wrong
Perhaps a 2nd web part is added..
Some libraries are installed using
npm (e.g. Angular)..
Bundling – how it goes wrong
gulp bundle --ship
gulp deploy-azure-storage
gulp package-solution --ship
SPFx deployment process:
Bundling – how it goes wrong
App package added to App Catalog:
Bundling – done wrong

More Related Content

PPTX
COB - Azure Functions for Office 365 developers
Chris O'Brien
 
PPTX
Chris O'Brien - Best bits of Azure for Office 365/SharePoint developers
Chris O'Brien
 
PPTX
Chris O'Brien - Comparing SharePoint add-ins (apps) with Office 365 apps
Chris O'Brien
 
PPTX
Chris O'Brien - Modern SharePoint development: techniques for moving code off...
Chris O'Brien
 
PPTX
Chris OBrien - Weaving Enterprise Solutions into Office Products
Chris O'Brien
 
PPTX
Application Lifecycle Management for Office 365 development
Chris O'Brien
 
PPTX
[Patel] SPFx: An ISV Insight into latest Microsoft's customization model
European Collaboration Summit
 
PPTX
Chris O'Brien - Modern SharePoint sites and the SharePoint Framework - reference
Chris O'Brien
 
COB - Azure Functions for Office 365 developers
Chris O'Brien
 
Chris O'Brien - Best bits of Azure for Office 365/SharePoint developers
Chris O'Brien
 
Chris O'Brien - Comparing SharePoint add-ins (apps) with Office 365 apps
Chris O'Brien
 
Chris O'Brien - Modern SharePoint development: techniques for moving code off...
Chris O'Brien
 
Chris OBrien - Weaving Enterprise Solutions into Office Products
Chris O'Brien
 
Application Lifecycle Management for Office 365 development
Chris O'Brien
 
[Patel] SPFx: An ISV Insight into latest Microsoft's customization model
European Collaboration Summit
 
Chris O'Brien - Modern SharePoint sites and the SharePoint Framework - reference
Chris O'Brien
 

What's hot (20)

PPTX
TypeScript and SharePoint Framework
Bob German
 
PDF
SPUnite17 Timer Jobs Event Handlers
NCCOMMS
 
PPTX
COB ESPC18 - Rich PowerApps with offline support
Chris O'Brien
 
PPTX
SharePoint Development with the SharePoint Framework
JoAnna Cheshire
 
PPTX
ECS19 Bert Jansen - Modernizing your existing sites
European Collaboration Summit
 
PPTX
SharePoint Framework - Developer Preview
Sean McLellan
 
PPTX
Modern SharePoint Development using Visual Studio Code
Jared Matfess
 
PDF
Create SASSy web parts in SPFx
Stefan Bauer
 
PDF
O365Con18 - Automate your Tasks through Azure Functions - Elio Struyf
NCCOMMS
 
PPTX
Application innovation & Developer Productivity
Kushan Lahiru Perera
 
PPTX
Azure Web Jobs
BizTalk360
 
PDF
[Struyf] Automate Your Tasks With Azure Functions
European Collaboration Summit
 
PDF
O365Con18 - Site Templates, Site Life Cycle Management and Modern SharePoint ...
NCCOMMS
 
PPTX
Introduction to ASP.NET
Peter Gfader
 
PPTX
Activate bots within SharePoint Framework
Kushan Lahiru Perera
 
PPTX
SharePoint PowerShell for the Admin and Developer - A Venn Diagram Experience
Ricardo Wilkins
 
PDF
SPUnite17 SPFx Extensions
NCCOMMS
 
PDF
SPUnite17 Introduction to the Office Dev PnP Core Libraries
NCCOMMS
 
PDF
O365Con18 - Implementing Automated UI Testing for SharePoint Solutions - Elio...
NCCOMMS
 
PPTX
COB - PowerApps - the good, the bad and the ugly - early 2018
Chris O'Brien
 
TypeScript and SharePoint Framework
Bob German
 
SPUnite17 Timer Jobs Event Handlers
NCCOMMS
 
COB ESPC18 - Rich PowerApps with offline support
Chris O'Brien
 
SharePoint Development with the SharePoint Framework
JoAnna Cheshire
 
ECS19 Bert Jansen - Modernizing your existing sites
European Collaboration Summit
 
SharePoint Framework - Developer Preview
Sean McLellan
 
Modern SharePoint Development using Visual Studio Code
Jared Matfess
 
Create SASSy web parts in SPFx
Stefan Bauer
 
O365Con18 - Automate your Tasks through Azure Functions - Elio Struyf
NCCOMMS
 
Application innovation & Developer Productivity
Kushan Lahiru Perera
 
Azure Web Jobs
BizTalk360
 
[Struyf] Automate Your Tasks With Azure Functions
European Collaboration Summit
 
O365Con18 - Site Templates, Site Life Cycle Management and Modern SharePoint ...
NCCOMMS
 
Introduction to ASP.NET
Peter Gfader
 
Activate bots within SharePoint Framework
Kushan Lahiru Perera
 
SharePoint PowerShell for the Admin and Developer - A Venn Diagram Experience
Ricardo Wilkins
 
SPUnite17 SPFx Extensions
NCCOMMS
 
SPUnite17 Introduction to the Office Dev PnP Core Libraries
NCCOMMS
 
O365Con18 - Implementing Automated UI Testing for SharePoint Solutions - Elio...
NCCOMMS
 
COB - PowerApps - the good, the bad and the ugly - early 2018
Chris O'Brien
 
Ad

Similar to Chris OBrien - Pitfalls when developing with the SharePoint Framework (SPFx) (20)

PPTX
Learn from my Mistakes - Building Better Solutions in SPFx
Thomas Daly
 
PPTX
SharePoint Framework tips and tricks
Giuseppe Marchi
 
PPTX
SharePoint Saturday Vienna Slides
David Opdendries
 
PDF
SPUnite17 Building Great Client Side Web Parts with SPFx
NCCOMMS
 
PPTX
SharePoint Framework, React and Office UI SPS Paris 2016 - d01
Sonja Madsen
 
PPTX
Office 365 Saturday (Sydney) - SharePoint framework – build integrated user e...
Anupam Ranku
 
PDF
SPS Paris: Building great client-side web parts with spfx, pnp-js-core, React...
Bill Ayers
 
PDF
D1 - Building Great Client-side Web Parts with SPFx, PnP-JS-Core, ReactJS and...
SPS Paris
 
PDF
How to convert your Full Trust Solutions to the SharePoint Framework (SPFx)
Brian Culver
 
PDF
Real World SharePoint Framework and Azure Services
Brian Culver
 
PPTX
ECS19 - Vesa Juvonen - SharePoint and Office 365 Development PowerClass
European Collaboration Summit
 
PPTX
What's new and what's next in SharePoint Development for Enterprise & SPFx
Vignesh Ganesan I Microsoft MVP
 
PPTX
SharePoint Framework, React, and Office UI sps Silicon Valley
Sonja Madsen
 
PPTX
Developing SharePoint Framework Solutions for the Enterprise (SPC 2019)
Eric Shupps
 
PPTX
The happy developer - SharePoint Framework React and Mindfulness
Olli Jääskeläinen
 
PDF
Convert your Full Trust Solutions to the SharePoint Framework (SPFx)
Brian Culver
 
PDF
How to convert your Full Trust Solutions to the SharePoint Framework (SPFx)
Brian Culver
 
PDF
Convert your Full Trust Solutions to the SharePoint Framework (SPFx)
Brian Culver
 
PPTX
SharePoint Saturday Zurich 2017 - SharePoint Framework the new development way
Giuliano De Luca
 
PPTX
SharePoint Fest Seattle 2018 - From SharePoint to Office 365 Development
Sébastien Levert
 
Learn from my Mistakes - Building Better Solutions in SPFx
Thomas Daly
 
SharePoint Framework tips and tricks
Giuseppe Marchi
 
SharePoint Saturday Vienna Slides
David Opdendries
 
SPUnite17 Building Great Client Side Web Parts with SPFx
NCCOMMS
 
SharePoint Framework, React and Office UI SPS Paris 2016 - d01
Sonja Madsen
 
Office 365 Saturday (Sydney) - SharePoint framework – build integrated user e...
Anupam Ranku
 
SPS Paris: Building great client-side web parts with spfx, pnp-js-core, React...
Bill Ayers
 
D1 - Building Great Client-side Web Parts with SPFx, PnP-JS-Core, ReactJS and...
SPS Paris
 
How to convert your Full Trust Solutions to the SharePoint Framework (SPFx)
Brian Culver
 
Real World SharePoint Framework and Azure Services
Brian Culver
 
ECS19 - Vesa Juvonen - SharePoint and Office 365 Development PowerClass
European Collaboration Summit
 
What's new and what's next in SharePoint Development for Enterprise & SPFx
Vignesh Ganesan I Microsoft MVP
 
SharePoint Framework, React, and Office UI sps Silicon Valley
Sonja Madsen
 
Developing SharePoint Framework Solutions for the Enterprise (SPC 2019)
Eric Shupps
 
The happy developer - SharePoint Framework React and Mindfulness
Olli Jääskeläinen
 
Convert your Full Trust Solutions to the SharePoint Framework (SPFx)
Brian Culver
 
How to convert your Full Trust Solutions to the SharePoint Framework (SPFx)
Brian Culver
 
Convert your Full Trust Solutions to the SharePoint Framework (SPFx)
Brian Culver
 
SharePoint Saturday Zurich 2017 - SharePoint Framework the new development way
Giuliano De Luca
 
SharePoint Fest Seattle 2018 - From SharePoint to Office 365 Development
Sébastien Levert
 
Ad

More from Chris O'Brien (18)

PPTX
Chris O'Brien - Building AI into Power Platform solutions
Chris O'Brien
 
PPTX
Chris OBrien - Azure DevOps for managing work
Chris O'Brien
 
PPTX
Chris O'Brien - Ignite 2019 announcements and selected roadmaps
Chris O'Brien
 
PPTX
Chris O'Brien - Intro to Power BI for Office 365 devs (March 2017)
Chris O'Brien
 
PPTX
Chris O'Brien - Introduction to the SharePoint Framework for developers
Chris O'Brien
 
PPTX
Do's and don'ts for Office 365 development
Chris O'Brien
 
PPTX
Chris O'Brien - Customizing the SharePoint/Office 365 UI with JavaScript (ESP...
Chris O'Brien
 
PPTX
Deep dive into SharePoint 2013 hosted apps - Chris OBrien
Chris O'Brien
 
PPTX
Customizing the SharePoint 2013 user interface with JavaScript - Chris OBrien
Chris O'Brien
 
PPTX
SP2013 for Developers - Chris O'Brien
Chris O'Brien
 
PPTX
Getting to grips with SharePoint 2013 apps - Chris O'Brien
Chris O'Brien
 
PPTX
SharePoint Ribbon Deep Dive
Chris O'Brien
 
PPTX
Automated Builds And UI Testing in SharePoint 2010 Development
Chris O'Brien
 
PPTX
Optimizing SharePoint 2010 Internet Sites
Chris O'Brien
 
PPTX
Managing the SharePoint 2010 Application Lifecycle - Part 2
Chris O'Brien
 
PPTX
Managing the SharePoint 2010 Application Lifecycle - Part 1
Chris O'Brien
 
PPT
SharePoint workflow deep-dive
Chris O'Brien
 
PPT
SharePoint Web Content Management - Lessons Learnt/top 5 tips
Chris O'Brien
 
Chris O'Brien - Building AI into Power Platform solutions
Chris O'Brien
 
Chris OBrien - Azure DevOps for managing work
Chris O'Brien
 
Chris O'Brien - Ignite 2019 announcements and selected roadmaps
Chris O'Brien
 
Chris O'Brien - Intro to Power BI for Office 365 devs (March 2017)
Chris O'Brien
 
Chris O'Brien - Introduction to the SharePoint Framework for developers
Chris O'Brien
 
Do's and don'ts for Office 365 development
Chris O'Brien
 
Chris O'Brien - Customizing the SharePoint/Office 365 UI with JavaScript (ESP...
Chris O'Brien
 
Deep dive into SharePoint 2013 hosted apps - Chris OBrien
Chris O'Brien
 
Customizing the SharePoint 2013 user interface with JavaScript - Chris OBrien
Chris O'Brien
 
SP2013 for Developers - Chris O'Brien
Chris O'Brien
 
Getting to grips with SharePoint 2013 apps - Chris O'Brien
Chris O'Brien
 
SharePoint Ribbon Deep Dive
Chris O'Brien
 
Automated Builds And UI Testing in SharePoint 2010 Development
Chris O'Brien
 
Optimizing SharePoint 2010 Internet Sites
Chris O'Brien
 
Managing the SharePoint 2010 Application Lifecycle - Part 2
Chris O'Brien
 
Managing the SharePoint 2010 Application Lifecycle - Part 1
Chris O'Brien
 
SharePoint workflow deep-dive
Chris O'Brien
 
SharePoint Web Content Management - Lessons Learnt/top 5 tips
Chris O'Brien
 

Recently uploaded (20)

PDF
A Day in the Life of Location Data - Turning Where into How.pdf
Precisely
 
PDF
Revolutionize Operations with Intelligent IoT Monitoring and Control
Rejig Digital
 
PPTX
cloud computing vai.pptx for the project
vaibhavdobariyal79
 
PDF
Advances in Ultra High Voltage (UHV) Transmission and Distribution Systems.pdf
Nabajyoti Banik
 
PDF
Using Anchore and DefectDojo to Stand Up Your DevSecOps Function
Anchore
 
PPTX
AI and Robotics for Human Well-being.pptx
JAYMIN SUTHAR
 
PDF
Presentation about Hardware and Software in Computer
snehamodhawadiya
 
PDF
How Onsite IT Support Drives Business Efficiency, Security, and Growth.pdf
Captain IT
 
PPTX
Comunidade Salesforce São Paulo - Desmistificando o Omnistudio (Vlocity)
Francisco Vieira Júnior
 
PDF
Oracle AI Vector Search- Getting Started and what's new in 2025- AIOUG Yatra ...
Sandesh Rao
 
PDF
Event Presentation Google Cloud Next Extended 2025
minhtrietgect
 
PDF
Chapter 2 Digital Image Fundamentals.pdf
Getnet Tigabie Askale -(GM)
 
PDF
GYTPOL If You Give a Hacker a Host
linda296484
 
PDF
Doc9.....................................
SofiaCollazos
 
PPTX
ChatGPT's Deck on The Enduring Legacy of Fax Machines
Greg Swan
 
PDF
CIFDAQ's Token Spotlight: SKY - A Forgotten Giant's Comeback?
CIFDAQ
 
PDF
Security features in Dell, HP, and Lenovo PC systems: A research-based compar...
Principled Technologies
 
PPTX
New ThousandEyes Product Innovations: Cisco Live June 2025
ThousandEyes
 
PDF
BLW VOCATIONAL TRAINING SUMMER INTERNSHIP REPORT
codernjn73
 
PDF
REPORT: Heating appliances market in Poland 2024
SPIUG
 
A Day in the Life of Location Data - Turning Where into How.pdf
Precisely
 
Revolutionize Operations with Intelligent IoT Monitoring and Control
Rejig Digital
 
cloud computing vai.pptx for the project
vaibhavdobariyal79
 
Advances in Ultra High Voltage (UHV) Transmission and Distribution Systems.pdf
Nabajyoti Banik
 
Using Anchore and DefectDojo to Stand Up Your DevSecOps Function
Anchore
 
AI and Robotics for Human Well-being.pptx
JAYMIN SUTHAR
 
Presentation about Hardware and Software in Computer
snehamodhawadiya
 
How Onsite IT Support Drives Business Efficiency, Security, and Growth.pdf
Captain IT
 
Comunidade Salesforce São Paulo - Desmistificando o Omnistudio (Vlocity)
Francisco Vieira Júnior
 
Oracle AI Vector Search- Getting Started and what's new in 2025- AIOUG Yatra ...
Sandesh Rao
 
Event Presentation Google Cloud Next Extended 2025
minhtrietgect
 
Chapter 2 Digital Image Fundamentals.pdf
Getnet Tigabie Askale -(GM)
 
GYTPOL If You Give a Hacker a Host
linda296484
 
Doc9.....................................
SofiaCollazos
 
ChatGPT's Deck on The Enduring Legacy of Fax Machines
Greg Swan
 
CIFDAQ's Token Spotlight: SKY - A Forgotten Giant's Comeback?
CIFDAQ
 
Security features in Dell, HP, and Lenovo PC systems: A research-based compar...
Principled Technologies
 
New ThousandEyes Product Innovations: Cisco Live June 2025
ThousandEyes
 
BLW VOCATIONAL TRAINING SUMMER INTERNSHIP REPORT
codernjn73
 
REPORT: Heating appliances market in Poland 2024
SPIUG
 

Chris OBrien - Pitfalls when developing with the SharePoint Framework (SPFx)

  • 1. Pitfalls when developing with the SharePoint Framework (SPFx) Chris O’Brien (MVP) Independent/Content and Code, UK Add Speaker Photo here
  • 2. Notes on this presentation If you have previously seen this presentation/slide deck before, note the following updates: Content Slides Pitfalls around Office UI Fabric 27-30 Pitfalls around calling the Microsoft Graph or custom APIs secured with Azure Active Directory 31-35 Use of SPFx component bundles 40-42
  • 4. Fundamentals – how it all works Packages installed/updated using npm • .NET analogy = NuGet Dependent JS libraries stored in node_modules • .NET analogy = the BIN directory • Gets bundled/deployed with your app Package.json records your top-level dependencies • .NET analogy = packages.config • Allows other devs to build app from source control • N.B. Each dependency may have IT’S OWN dependencies and package.json
  • 5. COB App - node_modules - jQuery - node_modules - cache-swap - node_modules - React - node_modules …… Simplified node_modules hierarchy
  • 6. Fundamentals - how to add a library Use npm install command e.g: npm install jquery Installs library to your app (in node_modules) Important parameter: --save OR --save-exact Usually add TypeScript typings (for auto-complete) npm install @types/jquery -–save
  • 7. Understanding package.json dependencies node • Lists all 3rd party libraries needed to run devDependencies node • Lists all 3rd party libraries needed to develop/build
  • 8. Semantic versioning (semver) Example Known as Meaning ^1.2.1 Caret dependency Greater than or equal to 1.2.1, but less than 2.0.0 ~1.2.1 Tilde dependency Greater than or equal to 1.2.1, but less than 1.3.0 1.2.1 Exact dependency 1.2.1 only Fundamentals 3 part version number – e.g. 1.0.0 Major.Minor.Patch Major = breaking change/substantial differences Minor = non-breaking e.g. new methods Patch = no interface changes e.g. optimisations, documentation
  • 9. Versioning/dependency pitfalls Using caret dependencies (the default) Not specifying – save on npm install Dev: Not locking dependencies down Shipping: Will change in npm 5!
  • 11. Dependencies and shipping The problem – “dependency float” • Your app has many JS dependencies (the node_modules tree) • node_modules should not be checked-in • Different version somewhere in tree -> Broken app The solution – npm shrinkwrap • Generates npm-shrinkwrap.json file Critical to getting a “100% reproducible build” • Locks down dependencies – for entire node_modules tree
  • 12. npm shrinkwrap Tip - check-in npm-shrinkwrap.json for each shipped release • Allows exact build to be recreated • Allows other devs to build exact app from source control Better than save-exact – deals with full dependency tree • save-exact only deals with top-level dependencies
  • 14. Remember the rule: = OK ^ = Not OK
  • 15. Recommendations – versioning etc. Pitfall How avoided More reading Avoid dependency issues in dev Ensure devs *save* packages properly – use npm install --save/--save-exact. Consider custom .npmrc file across team http://cob- sp.com/2fOtApJ Avoid dependency issues when shipping Use npm shrinkwrap for each release https://docs.npmjs. com/cli/shrinkwrap
  • 17. Code re-use pitfall Copy/pasting JS code into each app, because not clear how to re-use properly
  • 18. Re-using existing JS code Create a module for your code • Expose each method with exports statement: module.exports = { CheckRealValue: COB.CORE.Utilities.CheckRealValue, StringIsEmpty: COB.CORE.Utilities.StringIsEmpty } Create package.json file • Specify entry point (file)
  • 19. Re-using existing JS code Access module with ‘require’ • var cobUtil = require('cob-utility') • cobUtil.StringIsEmpty("foo");
  • 21. So, now you have a module. How to include/reference that?
  • 22. Some popular options Use npm LOCAL packages • Install from file path (COPY) or use NPM LINK Use node_modules higher up filesystem • Take advantage of “recurse upwards” approach of npm- See http://cob- sp.com/2eXDJOI Use private package hosting • npm private packages - $7 pm/user • VSTO private hosting - $4 pm/user Also consider: https://www.visualstudio.co m/en- us/docs/package/install
  • 23. Recommendations – code re-use Pitfall How More reading Copy/pasting JS code into each project Create modules for existing code Consider module strategy: • npm install [filepath] • npm link (for “parallel dev” of client and utility code) • Use of npm private packages etc. http://nicksellen.co. uk/2015/04/17/ho w-to-manage- private-npm- modules.html http://stackoverflo w.com/questions/2 1233108/cross- project-references- between-two- projects
  • 25. SPFX coding pitfalls Dealing with async code/ promises Calling the Microsoft Graph (permutations) Calling secure APIs (AAD)Office UI Fabric Adding a library TypeScript issues
  • 26. Pitfall – Office UI Fabric issues Problem: You want to use Fabric but are confused..
  • 27. Office UI Fabric • Office UI Fabric Core a.k.a. Fabric Core - this is a set of core styles, typography, a responsive grid, animations, icons, and other fundamental building blocks of the overall design language. • Office UI Fabric React a.k.a. Fabric React - this package contains a set of React components built on top of the Fabric design language.
  • 28. Pitfall – Office UI Fabric issues Problem: You want to use Fabric but are confused.. Solution: • To use Fabric Core easily, use SPFx v1.3.4 or later ( • Using React? Can use Fabric React components – use individual static links (for bundle size) Key npm packages: • office-ui-fabric- react • @microsoft/sp- office-ui-fabric- core (new)
  • 29. Correct use of Fabric React (bundling approach) WARNING – React styles are bundled with EACH web part in this approach. Mitigate with SPFx component bundles if you need to (e.g. expecting many of your web parts on page). See http://cob-sp.com/2hPVmUc
  • 30. Pitfall – calling the Graph/custom APIs Problem: You need to call the Graph or a custom API from SPFx (i.e. AAD-secured) Solution: • Understand today’s options: • GraphHttpClient (limited scenarios!) • AAD app + adal.js • AAD app + SPO auth cookie/IFrame approach • Understand a future option: • AAD app + tell SPFx to trust it
  • 31. Graph/custom API permutations - GraphHttpClient - or more likely, use of adal.js Calling the Graph from client-side - adal.js - SPO auth cookie/IFrame Calling custom API (AAD) from client-side •- adal.js from client (SPO auth cookie approach gives token which cannot be used with Graph) - adal.NET within custom API OR - New Azure Functions bindings (preview – can’t get to work!) - Use of both “on behalf of user” and “app-only” Calling custom API (AAD) from client-side which calls the Graph Reference: Connect to API secured with AAD - http://cob- sp.com/SPFx-AAD
  • 32. Cheat sheet - custom APIs/Azure Functions with AAD ADAL.js • CORS – define rule for each calling page • Code - Ensure asking for token for your resource (AAD client ID) SPO auth cookie approach • Empty CORS rules • Code: • Pass “credentials” : “include” header, and sure API/Function can receive.. • IFrame onto Function URL Reference: Connect to API secured with AAD - http://cob- sp.com/SPFx-AAD CONSIDER: • Each web part/extension on page must sign-in • AAD reply URL needed for each page with WP (max 10!) CONSIDER: • Sign-in applies to entire page/session • Cannot access user identity (app-only)
  • 33. Future option – Graph/customAPIs Graph - Specify additional permission scopes for GraphHttpClient e.g. I’m OK with all SPFx web parts having access to more than Groups and Reports Your APIs/Azure Functions Specify additional custom APIs for same token Benefit – no need for sign-in button in your WP/extension Dev preview late 2017? { "WebApiPermissionRequest": { "ResourceId": “GUID goes here", "Scope": “GUID goes here", } "WebApiPermissionRequest": { "ResourceId": “GUID goes here", "Scope": “GUID goes here", } "WebApiPermissionRequest": { "ResourceId": “GUID goes here", "Scope": “GUID goes here", }
  • 34. Recommendations – coding Pitfall How avoided More reading Office UI Fabric issues Get familiar with: • Fabric Core vs. Fabric React components • SPFx 1.3.4/sp-office-ui-fabric-core package • Using mixins in your SCSS http://cob-sp.com/SPFx- OUIF Graph/custom API issues Get familiar with: • Register AAD apps + adal.js • SPO auth cookie approach • Future SPFx option http://cob-sp.com/SPFx-AAD Async code issues Get familiar with: • Promises http://cob-sp.com/SPFX- Promises Security issues Avoid SPFX if sensitive data sent to client (page or JS) - use Add-in parts/IFrames if needed http://cob-sp.com/2ez9JNX
  • 36. Pitfalls - deployment Accidentally bundling external libraries/frameworks Accidentally shipping a debug build Losing track of remote JS code
  • 37. Bundling considerations Librariesare includedin your bundle BY DEFAULT Update config.json if (e.g.) jQuery should be referenced from CDN One bundleper web part BY DEFAULT - across your site 10 web parts = 10 different copies of jQuery being downloaded GUID in bundleURL is regeneratedon each build This is the versioning/cache-busting mechanism TIP – delete unused JS files from CDN to keep things tidy
  • 39. Bundling – rule #1 “Externalise” where possible (CDN):
  • 40. Bundling – rule #2 Ensure any libs you ARE bundling are consolidated (with SPFx component bundles): WP1 WP2 cob-bothWebParts.js
  • 41. Recommendations – deployment Pitfall How avoided More reading Accidental bundling Ensure libs loaded externally where possible Update “externals” section of config.json Waldek - http://cob- sp.com/2frVMR3 Duplication of code in bundle Use SPFx component bundles Elio - http://cob- sp.com/SPFx- CompBundle Losing track of remote JS code • Proactively track CDN locations (e.g. Excel?) • Use SPCAF to help identify www.spcaf.com
  • 42. Key take-aways It’s a new world, with different pitfalls! Recommendations: Get familiar with NPM especially Plan for code re-use (e.g. modules) if appropriate Practice “production” deployments Dependencies/versioning e.g. dependency float Coding e.g. OUIF, calling the Graph or custom APIs Deployment e.g. accidental bundling, duplication in bundle
  • 43. Thank you!!  Any questions? www.sharepointnutsandbolts.com
  • 44. Bundling – how it goes wrong Perhaps a 2nd web part is added.. Some libraries are installed using npm (e.g. Angular)..
  • 45. Bundling – how it goes wrong gulp bundle --ship gulp deploy-azure-storage gulp package-solution --ship SPFx deployment process:
  • 46. Bundling – how it goes wrong App package added to App Catalog: