-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Polaris V8 migration guide #4987
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
Merged
Merged
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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,86 @@ | ||
| # Migrating from v7 to v8 | ||
|
|
||
| Polaris v8.0.0 ([full release notes](https://github.com/Shopify/polaris-react/releases/tag/v8.0.0)) features a change to the required node version and root font size. | ||
|
|
||
| ## Node support | ||
|
|
||
| Node 16 is now a requirement. | ||
|
|
||
| ## Base font size | ||
|
|
||
| ~~`html {font-size: 62.5%}`~~ | ||
|
|
||
| `html {font-size: 100%}` | ||
|
|
||
| No changes are needed if your app uses the `rem()` function for css values. If your app caches css files you'll need to rebuild them once you upgrade to v8.0.0. | ||
|
|
||
| Polaris has switched to the browser default of 16px for its base font size instead of the previous 10px. | ||
|
|
||
| If you have hard coded rem values then you will need to modify them to use the `rem()` function or recalculate them accordingly: | ||
|
|
||
| `rem(16px) => 1.6rem` is no longer true (16 / 10). | ||
|
|
||
| `rem(16px) => 1rem` is the new conversion (16 / 16). | ||
|
|
||
| We've created the following codemod to help with manually set rem values: | ||
|
|
||
| <details> | ||
| <summary>Codemod to convert hard coded rems</summary> | ||
|
|
||
| ```jsx | ||
| // node index.js <target-path> | ||
| | ||
| import fs from 'fs/promises' | ||
| import path from 'path' | ||
| import os from 'os' | ||
| | ||
| import pMap from 'p-map' | ||
| import { globby } from 'globby' | ||
| | ||
| const target = path.resolve(process.cwd(), process.argv[2]) | ||
| | ||
| const stats = { | ||
| files: 0, | ||
| rems: 0, | ||
| } | ||
| | ||
| if (!target) { | ||
| console.log('Please specify a target directory') | ||
| process.exit(1) | ||
| } | ||
| | ||
| const scssPaths = await globby('**/*.scss', { | ||
| cwd: target, | ||
| ignore: ['**/node_modules/**/*.scss'], | ||
| absolute: true, | ||
| }) | ||
| | ||
| console.log(`Checking for rems in ${scssPaths.length} file(s)\n`) | ||
| | ||
| async function replaceRems(filePath) { | ||
| let hasRems = false | ||
| const fileContent = await fs.readFile(filePath, { encoding: 'utf8' }) | ||
| const remRegex = /(-?\d+(?:\.\d+|\d*))rem/g | ||
| | ||
| const newContent = fileContent.replace(remRegex, (_, unit) => { | ||
| hasRems = true | ||
| stats.rems++ | ||
| | ||
| const value = parseFloat(unit) * 10 // Note: 1rem was previously 10px | ||
| | ||
| return `rem(${value}px)` | ||
| }) | ||
| | ||
| if (hasRems) stats.files++ | ||
| | ||
| await fs.writeFile(filePath, newContent) | ||
| } | ||
| | ||
| await pMap(scssPaths, replaceRems, { concurrency: os.cpus().length }) | ||
| | ||
| console.log(`Updated ${stats.rems} rems in ${stats.files} files\n`) | ||
| | ||
| console.log('Done! 🌈') | ||
| ``` | ||
|
|
||
| </details> | ||
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.
❤️