[polaris.shopify.com] Move examples to app directory #8574
Closed
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.
The problem
The way we currently solve this is by adding both stylesheets to the website. If you inspect the elements on the site, you can see traces of Polaris styles, like CSS variables prefixed with
--p-
.It's not too bad, but it messes with the website styles in small ways all over the place. It's also unclear to website contributors wether or not they should rely on Polaris styles and variables (they shouldn't).
The solution
Next.js 13 adds a new feature, namely to use different global stylesheets for different routes:
/examples
<- Use Polaris stylesheets/anything-else
<- Use website stylesheetsThis is part of the new
App dir
feature in Next.js 13.What this PR does
It adds two scripts:
move-examples.mjs
— A one time migration that moves the examples toapp/examples
.fix-examples.mjd
— Updates the relative imports inside examples and adds'use client';
to them (to let Next.js 13 know that these shouldn't be server rendered).layout.tsx
files to theapp
directory. These are needed to render the examples at their new location. They also help apply the Polaris stylesheets to the examples.next.config.ts
to enable the experimental "app dir" from next.js 13tsconfig.json
to use a next plugin. I'm not sure exactly what it does, but I think it's part of next.js 13.--p-
values that are no longer present in the website stylesheet.What's next
We've shipped a ton of features to the website lately which is awesome! However, it's getting quite messy. I'll give it some love over the coming weeks.