Skip to content

react-styles: Fix .mjs component CSS imports#7971

Merged
tlabaj merged 29 commits into
patternfly:mainfrom
jschuler:react-styles-mjs-css-imports
Sep 13, 2022
Merged

react-styles: Fix .mjs component CSS imports#7971
tlabaj merged 29 commits into
patternfly:mainfrom
jschuler:react-styles-mjs-css-imports

Conversation

@jschuler
Copy link
Copy Markdown
Collaborator

@jschuler jschuler commented Sep 13, 2022

What: Closes #7960

react-styles creates *.mjs files for bundlers that support them (like create-react-app). Currently they import component css like this: import('./page.css') which is using the import function. That results in CSS being loaded asynchronously, and can result in the issue above.
This PR changes it to be a regular import statement import './page.css'.

Thanks to @mcoker for finding the load ordering issue and providing nice codesandbox examples of what it looks like before and after the react-styles change that introduced the issue

The issue:

Before: The custom stylesheet (index.css) is loaded at the end as expected
Screen Shot 2022-09-12 at 3 02 06 PM

After: The custom stylesheet is loaded earlier since the react-core/styles component CSS was loaded lazily
Screen Shot 2022-09-12 at 3 03 00 PM

Verified the fix by loading up the user's workspace in issue #7960 , and temporarily changing the react-styles *.mjs CSS imports

In VSCode find/replace, enable regex search .*
Find: import\('(.*)'\)
Replace: import '$1'
Files to include: ./web/node_modules/@patternfly/react-styles/css/components/**/*.mjs

Repo that reproduces the issue
https://github.com/jschuler/react-styles-css-load-order

jschuler and others added 29 commits September 3, 2021 13:50
@patternfly-build
Copy link
Copy Markdown
Collaborator

patternfly-build commented Sep 13, 2022

Copy link
Copy Markdown
Contributor

@tlabaj tlabaj left a comment

Choose a reason for hiding this comment

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

lgtm

@tlabaj tlabaj merged commit c555b1b into patternfly:main Sep 13, 2022
@patternfly-build
Copy link
Copy Markdown
Collaborator

Your changes have been released in:

  • eslint-plugin-patternfly-react@4.76.10
  • @patternfly/react-catalog-view-extension@4.88.10
  • @patternfly/react-charts@6.90.10
  • @patternfly/react-code-editor@4.78.10
  • @patternfly/react-console@4.88.10
  • @patternfly/react-core@4.237.10
  • @patternfly/react-docs@5.98.10
  • @patternfly/react-icons@4.88.10
  • @patternfly/react-inline-edit-extension@4.82.10
  • demo-app-ts@4.197.10
  • @patternfly/react-integration@4.199.10
  • @patternfly/react-log-viewer@4.82.10
  • @patternfly/react-styles@4.87.10
  • @patternfly/react-table@4.106.10
  • @patternfly/react-tokens@4.89.10
  • @patternfly/react-topology@4.84.10
  • @patternfly/react-virtualized-extension@4.84.10
  • transformer-cjs-imports@4.75.10

Thanks for your contribution! 🎉

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Bug - Page - navbar regressions due to Toolbar/PageHeaderTools responsiveness

4 participants