Skip to content
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

Convert amp example to TypeScript #37744

Merged
merged 4 commits into from
Jun 18, 2022

Conversation

maxproske
Copy link
Contributor

@maxproske maxproske commented Jun 16, 2022

Converted AMP example over to TypeScript to match the Contribution guidelines, updated all dependencies, and made some necessary changes to allow AMP apps to build in TypeScript.

I added an additional .d.ts file, and referenced it in the tsconfig.json include array, as per the Next.js docs. These additional types are required to allow lowercase AMP elements to be a property on JSX.IntrinsicElements.

Fixes:

Property 'amp-img' does not exist on type 'JSX.IntrinsicElements'.ts

I also replaced all occurrences of styled JSX with @ijjk's workaround to get styles in the head at build time for AMP-only pages, hybrid AMP pages, and normal pages (non-AMP).

I tried using the useAmp hook first with multiple <style jsx> like this Next.js discussion, however AMP expects a single <style amp-custom> tag in the head.

Fixes:

The parent tag of tag 'style amp-custom' is 'body', but it can only be 'head'

Documentation / Examples

  • Make sure the linting passes by running pnpm lint
  • The examples guidelines are followed from our contributing doc

@ijjk ijjk added the examples Issue/PR related to examples label Jun 16, 2022
Copy link
Member

@ijjk ijjk left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I re-added the usage of styled-jsx here instead of the _document as that's the default we recommend for AMP but looks good other than that, thanks for the PR!

@kodiakhq kodiakhq bot merged commit 1ccf894 into vercel:canary Jun 18, 2022
@maxproske
Copy link
Contributor Author

Thanks @ijjk! However, it appears your re-adding the usage of styled-jsx prevents the example from building.

pnpm build

...

error  The parent tag of tag 'style amp-custom' is 'body', but it can only be 'head'.  https://amp.dev/documentation/guides-and-tutorials/learn/spec/amphtml/#stylesheets
error  The parent tag of tag 'style amp-custom' is 'body', but it can only be 'head'.  https://amp.dev/documentation/guides-and-tutorials/learn/spec/amphtml/#stylesheets            
error  The parent tag of tag 'style amp-custom' is 'body', but it can only be 'head'.  https://amp.dev/documentation/guides-and-tutorials/learn/spec/amphtml/#stylesheets

> Build error occurred
Error: AMP Validation caused the export to fail. https://nextjs.org/docs/messages/amp-export-validation

If styled-jsx is the recommended default, I'd to figure out the correct usage to put this discussion to rest: #16755

@ijjk
Copy link
Member

ijjk commented Jun 18, 2022

@maxproske that was due to a bug on stable which is fixed in the latest canary of Next.js v12.1.7-canary.41, please update and give it a try!

@maxproske
Copy link
Contributor Author

@ijjk I updated and encounter the same error on v12.1.7-canary.41 and canary.

@ijjk
Copy link
Member

ijjk commented Jun 18, 2022

Are you sure the latest canary is installed correctly? I'm not seeing any errors with the example:

Screen Shot 2022-06-18 at 5 51 54 PM

@maxproske
Copy link
Contributor Author

@ijjk You're completely right, it works! I was still on v12.1.7-canary.10.

Thanks for making contributing to Next.js fun! 😄

kodiakhq bot pushed a commit that referenced this pull request Jun 26, 2022
Converted AMP First Boilerplate example over to TypeScript to match the Contribution guidelines.

Note: Requires `v12.1.7-canary.41` or newer to build #37744 (comment)

## Documentation / Examples

- [X] Make sure the linting passes by running `pnpm lint`
- [X] The examples guidelines are followed from [our contributing doc](https://github.com/vercel/next.js/blob/canary/contributing.md#adding-examples)
kodiakhq bot pushed a commit that referenced this pull request Jun 27, 2022
Converted AMP Story example over to TypeScript to align with the Examples guide.

Note: Requires `v12.1.7-canary.41` or newer to build #37744 (comment)

## Documentation / Examples

- [X] Make sure the linting passes by running `pnpm lint`
- [X] The examples guidelines are followed from [our contributing doc](https://github.com/vercel/next.js/blob/canary/contributing.md#adding-examples)
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Jul 19, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
examples Issue/PR related to examples
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants