New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Adding GoogleMaps and Youtube embed components #52909
Merged
Merged
Changes from all commits
Commits
Show all changes
70 commits
Select commit
Hold shift + click to select a range
4beb690
Setting up third-parties package
janicklas-ralph 4590570
Remove unwanted code
janicklas-ralph 857a189
Merge branch 'canary' of github.com:vercel/next.js into tpc
janicklas-ralph ddf4e41
Remove GA. Update import paths
janicklas-ralph 20ba09d
Add comments
janicklas-ralph d4933f0
Merge branch 'canary' of github.com:vercel/next.js into tpc
janicklas-ralph 38a8e96
Merge branch 'canary' of github.com:vercel/next.js into tpc
janicklas-ralph 1af8446
Fix lint
janicklas-ralph 16a7bac
Merge branch 'canary' of github.com:vercel/next.js into tpc
janicklas-ralph 8f51c4c
Fix lint
janicklas-ralph ebc5710
Merge branch 'canary' of github.com:vercel/next.js into tpc
janicklas-ralph 5881260
Fix review comments
janicklas-ralph 83e6ff0
Merge branch 'canary' of github.com:vercel/next.js into tpc
janicklas-ralph 0fe1533
Move outdent and prettier into devDependencies since we use them only…
janicklas-ralph ae5ed8c
Update lock file
janicklas-ralph 7e9e0d9
Merge branch 'canary' of github.com:vercel/next.js into tpc
janicklas-ralph ae7f11a
Marking third-parties as private
janicklas-ralph 5e2180b
Merge branch 'canary' of github.com:vercel/next.js into tpc
janicklas-ralph f5a9b50
remove console.log
huozhi 7f784cb
Merge branch 'canary' of github.com:vercel/next.js into tpc
janicklas-ralph 2d4cd2c
Merge branch 'tpc' of github.com:janicklas-ralph/next.js into tpc
janicklas-ralph f1066a1
Merge branch 'canary' of github.com:vercel/next.js into tpc
janicklas-ralph 5e5da7d
Modifying stylesheet loading. Loading stylesheets only for appDir
janicklas-ralph 93ed720
Merge branch 'canary' of github.com:vercel/next.js into tpc
janicklas-ralph ca57ab1
Remove unused test
janicklas-ralph d7f8c8e
Handle stylesheet for pages dir
janicklas-ralph 07b5a4e
Merge branch 'canary' of github.com:vercel/next.js into tpc
janicklas-ralph 1cd8274
Merge branch 'canary' of github.com:vercel/next.js into tpc
janicklas-ralph 912b3ef
Update lock file
janicklas-ralph aabab89
fix error
janicklas-ralph ba5ea22
fix types
janicklas-ralph ba00c27
Merge branch 'canary' of github.com:vercel/next.js into tpc
janicklas-ralph bb48cf1
refactor stylesheet loading with ReactDOM.preinit
janicklas-ralph de1a007
Merge branch 'canary' of github.com:vercel/next.js into tpc
janicklas-ralph 621f0a7
Trigger build
janicklas-ralph c22aa26
Merge branch 'canary' of github.com:vercel/next.js into tpc
janicklas-ralph 9bb65ba
Fix lint
janicklas-ralph 4090fca
Merge branch 'canary' of github.com:vercel/next.js into tpc
janicklas-ralph e84f165
Merge branch 'canary' of github.com:vercel/next.js into tpc
janicklas-ralph 5e1cf89
Merge branch 'canary' of github.com:vercel/next.js into tpc
janicklas-ralph f4636fd
Merge branch 'canary' of github.com:vercel/next.js into tpc
janicklas-ralph 8673256
Adding GoogleMaps and Youtube embed components
janicklas-ralph 4e4ce54
Update readme
janicklas-ralph 783849b
Merge branch 'canary' of github.com:vercel/next.js into tpc
janicklas-ralph d4f6b24
Fix review comments
janicklas-ralph ad7a98e
Merge branch 'canary' of github.com:vercel/next.js into tpc
janicklas-ralph adbfbfc
Merge branch 'canary' of github.com:vercel/next.js into tpc
janicklas-ralph 556342d
Merge branch 'canary' of github.com:vercel/next.js into tpc
janicklas-ralph 08eb415
Update third-parties components and tests
janicklas-ralph 2c470f7
Remove integration tests and move to e2e
janicklas-ralph b96a0f8
Merge branch 'canary' of github.com:vercel/next.js into tpc
janicklas-ralph cf5f23e
Updating tests with createNextDescribe
janicklas-ralph 4de98c4
Update tpc version
janicklas-ralph a30ed35
Merge branch 'canary' of github.com:vercel/next.js into tpc
janicklas-ralph c97b2f8
Merge branch 'canary' of github.com:vercel/next.js into tpc
janicklas-ralph 0b2dd4f
Update package.json
janicklas-ralph 43a0392
Update package.json
janicklas-ralph 4ef700b
Update tsconfig compile options
janicklas-ralph a097f14
Fix test cases
janicklas-ralph 8e691a9
Merge branch 'canary' of github.com:vercel/next.js into tpc
janicklas-ralph 216878d
Merge branch 'canary' of github.com:vercel/next.js into tpc
janicklas-ralph 19fa520
Merge branch 'canary' of github.com:vercel/next.js into tpc
janicklas-ralph 79dd2b1
Merge branch 'canary' of github.com:vercel/next.js into tpc
janicklas-ralph 5007ce0
Update readme
janicklas-ralph 4f5c760
Merge branch 'canary' of github.com:vercel/next.js into tpc
janicklas-ralph 3b23593
Remove extra loading prop
janicklas-ralph b05f5f1
Fix test
janicklas-ralph b673935
Merge branch 'canary' of github.com:vercel/next.js into tpc
janicklas-ralph 3d1e694
Update tests
janicklas-ralph ac95f83
Merge branch 'canary' into tpc
kodiakhq[bot] File filter
Filter by extension
Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
# Experimental `@next/third-parties` | ||
|
||
`@next/third-parties` is a collection of components and utilities that can be used to efficiently load third-party libraries into your Next.js application. | ||
|
||
> Note: `@next/third-parties` is still experimental and under active development. | ||
|
||
# Usage | ||
|
||
## Google Third-Parties | ||
|
||
### YouTube Embed | ||
|
||
The `YoutubeEmbed` component is used to load and display a YouTube embed. This component loads faster by using [lite-youtube-embed](https://github.com/paulirish/lite-youtube-embed) under the hood. | ||
|
||
```js | ||
import { YoutubeEmbed } from '@next/third-parties/google' | ||
|
||
export default function Page() { | ||
return <YoutubeEmbed videoid="ogfYd705cRs" height={400} /> | ||
} | ||
``` | ||
|
||
### Google Maps Embed | ||
|
||
The `GoogleMapsEmbed` component can be used to add a [Google Maps Embed](https://developers.google.com/maps/documentation/embed/get-started) to your page. By default, it uses the `loading` attribute to lazy-load below the fold. | ||
|
||
```js | ||
import { GoogleMapsEmbed } from '@next/third-parties/google' | ||
|
||
export default function Page() { | ||
return ( | ||
<GoogleMapsEmbed | ||
apiKey="XYZ" | ||
height={200} | ||
width="100%" | ||
mapMode="place" | ||
parameters="q=Brooklyn+Bridge,New+York,NY" | ||
/> | ||
) | ||
} | ||
``` | ||
|
||
To get a better idea of how these components work, take a look at this [demo](https://test-next-script-housseindjirdeh.vercel.app/). <!--- TODO: Replace with a better demo page --> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
/** | ||
* This is an autogenerated file by update-third-parties.js | ||
*/ | ||
import React from 'react' | ||
import Script from 'next/script' | ||
|
||
import ThirdPartyScriptEmbed from '../ThirdPartyScriptEmbed' | ||
import * as Types from '../types/google' | ||
|
||
// Embed a Google Maps embed on your webpage | ||
export function GoogleMapsEmbed(args: Types.GoogleMapsEmbed) { | ||
return ( | ||
<ThirdPartyScriptEmbed | ||
height={args.height || null} | ||
width={args.width || null} | ||
content={`<iframe loading="lazy" src="https://www.google.com/maps/embed/v1/${args.mapMode}?key=${args.apiKey}&${args.parameters}" width=${args.width} height=${args.height} style=${args.style} allowfullscreen=${args.allowfullscreen} referrerpolicy="no-referrer-when-downgrade"></iframe>`} | ||
dataNtpc="GoogleMapsEmbed" | ||
></ThirdPartyScriptEmbed> | ||
) | ||
} | ||
// Embed a YouTube embed on your webpage. | ||
export function YoutubeEmbed(args: Types.YoutubeEmbed) { | ||
return ( | ||
<ThirdPartyScriptEmbed | ||
height={args.height || null} | ||
width={args.width || null} | ||
content={`<lite-youtube videoid=${args.videoid} playlabel=${args.playlabel}></lite-youtube>`} | ||
dataNtpc="YoutubeEmbed" | ||
> | ||
<Script | ||
src={`https://cdn.jsdelivr.net/gh/paulirish/lite-youtube-embed@master/src/lite-yt-embed.js`} | ||
strategy="lazyOnload" | ||
// @ts-ignore | ||
stylesheets={[ | ||
'https://cdn.jsdelivr.net/gh/paulirish/lite-youtube-embed@master/src/lite-yt-embed.css', | ||
]} | ||
/> | ||
</ThirdPartyScriptEmbed> | ||
) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
export type GoogleMapsEmbed = { | ||
height?: number | ||
width?: number | ||
mapMode: 'place' | 'view' | 'directions' | 'streetview' | 'search' | ||
apiKey: string | ||
parameters: string | ||
style: string | ||
allowfullscreen: boolean | ||
loading: 'eager' | 'lazy' | ||
} | ||
|
||
export type YoutubeEmbed = { | ||
height?: number | ||
width?: number | ||
videoid: string | ||
playlabel?: string | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
18 changes: 18 additions & 0 deletions
18
test/e2e/app-dir/third-parties/app/google-maps-embed/page.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
import { GoogleMapsEmbed } from '@next/third-parties/google' | ||
|
||
const Page = () => { | ||
return ( | ||
<div class="container"> | ||
<h1>Google Maps Embed</h1> | ||
<GoogleMapsEmbed | ||
apiKey="XYZ" | ||
height={200} | ||
width="100%" | ||
mapMode="place" | ||
parameters="q=Brooklyn+Bridge,New+York,NY" | ||
/> | ||
</div> | ||
) | ||
} | ||
|
||
export default Page |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
export default function Root({ children }: { children: React.ReactNode }) { | ||
return ( | ||
<html> | ||
<body>{children}</body> | ||
</html> | ||
) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
import { YoutubeEmbed } from '@next/third-parties/google' | ||
|
||
const Page = () => { | ||
return ( | ||
<div class="container"> | ||
<h1>Youtube Embed</h1> | ||
<YoutubeEmbed videoid="ogfYd705cRs" height={400} /> | ||
</div> | ||
) | ||
} | ||
|
||
export default Page |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
import { createNextDescribe } from 'e2e-utils' | ||
|
||
createNextDescribe( | ||
'@next/third-parties basic usage', | ||
{ | ||
files: __dirname, | ||
dependencies: { | ||
'@next/third-parties': 'canary', | ||
}, | ||
}, | ||
({ next }) => { | ||
it('renders YoutubeEmbed', async () => { | ||
const $ = await next.render$('/youtube-embed') | ||
|
||
const baseContainer = $('[data-ntpc="YoutubeEmbed"]') | ||
const youtubeContainer = $('lite-youtube') | ||
expect(baseContainer.length).toBe(1) | ||
expect(youtubeContainer.length).toBe(1) | ||
}) | ||
|
||
it('renders GoogleMapsEmbed', async () => { | ||
const $ = await next.render$('/google-maps-embed') | ||
|
||
const baseContainer = $('[data-ntpc="GoogleMapsEmbed"]') | ||
const mapContainer = $( | ||
'[src="https://www.google.com/maps/embed/v1/place?key=XYZ&q=Brooklyn+Bridge,New+York,NY"]' | ||
) | ||
expect(baseContainer.length).toBe(1) | ||
expect(mapContainer.length).toBe(1) | ||
}) | ||
} | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
import { createNextDescribe } from 'e2e-utils' | ||
|
||
createNextDescribe( | ||
'@next/third-parties basic usage', | ||
{ | ||
files: __dirname, | ||
dependencies: { | ||
'@next/third-parties': 'canary', | ||
}, | ||
}, | ||
({ next }) => { | ||
it('renders YoutubeEmbed', async () => { | ||
const $ = await next.render$('/youtube-embed') | ||
|
||
const baseContainer = $('[data-ntpc="YoutubeEmbed"]') | ||
const youtubeContainer = $('lite-youtube') | ||
expect(baseContainer.length).toBe(1) | ||
expect(youtubeContainer.length).toBe(1) | ||
}) | ||
|
||
it('renders GoogleMapsEmbed', async () => { | ||
const $ = await next.render$('/google-maps-embed') | ||
|
||
const baseContainer = $('[data-ntpc="GoogleMapsEmbed"]') | ||
const mapContainer = $( | ||
'[src="https://www.google.com/maps/embed/v1/place?key=XYZ&q=Brooklyn+Bridge,New+York,NY"]' | ||
) | ||
expect(baseContainer.length).toBe(1) | ||
expect(mapContainer.length).toBe(1) | ||
}) | ||
} | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
import { GoogleMapsEmbed } from '@next/third-parties/google' | ||
|
||
const Page = () => { | ||
return ( | ||
<div class="container"> | ||
<h1>Google Maps Embed</h1> | ||
<GoogleMapsEmbed | ||
apiKey="XYZ" | ||
height={200} | ||
width="100%" | ||
mapMode="place" | ||
parameters="q=Brooklyn+Bridge,New+York,NY" | ||
/> | ||
</div> | ||
) | ||
} | ||
|
||
export default Page |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
import { YoutubeEmbed } from '@next/third-parties/google' | ||
|
||
const Page = () => { | ||
return ( | ||
<div class="container"> | ||
<h1>Youtube Embed</h1> | ||
<YoutubeEmbed videoid="ogfYd705cRs" height={400} /> | ||
</div> | ||
) | ||
} | ||
|
||
export default Page |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not super important, and not relevant for this PR, but @janicklas-ralph do you think it would be better to have this component named
<YouTubeEmbed>
instead? If so, I can update Third Party Capital's export and we can submit an additional PR that just runs the build script againThere was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sure
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Since you're using version 1.0.18 now, I think it's easier if we just update the export naming to
YouTubeEmbed
now to match Third Party Capital instead of pushing out a new PRThere was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@janicklas-ralph Are we planning on changing this in this PR or a follow-up?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It looks like we downgraded back to
1.0.17
in this PR. I think the plan is to do this in a follow-up PR once upgrading to the latest version.