Skip to content

feat: support design tokens and paragon 23 #1436

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

Conversation

dcoa
Copy link
Contributor

@dcoa dcoa commented Feb 27, 2025

Warning

This PR should not be merge to master directly, it should point to master-design-tokens once the branch has been created.

Description

This PR updates frontend app authn to support CSS variables and the corresponding paragon design tokens.

Changes implemented:

  • Replace Paragon SCSS variables with CSS variables.

Important

This PR requires a compatible version with paragon 23 of dependencies, because of that the following PRs need to be merged first:

How to test

Navigate the sandbox

@dcoa dcoa requested a review from a team as a code owner February 27, 2025 22:44
@openedx-webhooks openedx-webhooks added the open-source-contribution PR author is not from Axim or 2U label Feb 27, 2025
@openedx-webhooks
Copy link

openedx-webhooks commented Feb 27, 2025

Thanks for the pull request, @dcoa!

This repository is currently maintained by @openedx/2u-infinity.

Once you've gone through the following steps feel free to tag them in a comment and let them know that your changes are ready for engineering review.

🔘 Get product approval

If you haven't already, check this list to see if your contribution needs to go through the product review process.

  • If it does, you'll need to submit a product proposal for your contribution, and have it reviewed by the Product Working Group.
    • This process (including the steps you'll need to take) is documented here.
  • If it doesn't, simply proceed with the next step.
🔘 Provide context

To help your reviewers and other members of the community understand the purpose and larger context of your changes, feel free to add as much of the following information to the PR description as you can:

  • Dependencies

    This PR must be merged before / after / at the same time as ...

  • Blockers

    This PR is waiting for OEP-1234 to be accepted.

  • Timeline information

    This PR must be merged by XX date because ...

  • Partner information

    This is for a course on edx.org.

  • Supporting documentation
  • Relevant Open edX discussion forum threads
🔘 Get a green build

If one or more checks are failing, continue working on your changes until this is no longer the case and your build turns green.


Where can I find more information?

If you'd like to get more details on all aspects of the review process for open source pull requests (OSPRs), check out the following resources:

When can I expect my changes to be merged?

Our goal is to get community contributions seen and reviewed as efficiently as possible.

However, the amount of time that it takes to review and merge a PR can vary significantly based on factors such as:

  • The size and impact of the changes that it introduces
  • The need for product review
  • Maintenance status of the parent repository

💡 As a result it may take up to several weeks or months to complete a review and merge your PR.

@github-project-automation github-project-automation bot moved this to Needs Triage in Contributions Feb 27, 2025
@dcoa dcoa marked this pull request as draft February 27, 2025 22:44
@dcoa dcoa changed the title Dcoa/design tokens support [WIP] feat: support design tokens and paragon 23 Feb 27, 2025
@dcoa dcoa force-pushed the dcoa/design-tokens-support branch from 4df75f7 to c707d82 Compare February 27, 2025 22:59
@mphilbrick211 mphilbrick211 moved this from Needs Triage to Waiting on Author in Contributions Mar 3, 2025
@dcoa dcoa force-pushed the dcoa/design-tokens-support branch from c707d82 to b4faf7a Compare March 18, 2025 07:18
Copy link

codecov bot commented Mar 18, 2025

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 87.69%. Comparing base (2ea7637) to head (aa5a949).
Report is 1 commits behind head on master-design-tokens.

Additional details and impacted files
@@                  Coverage Diff                  @@
##           master-design-tokens    #1436   +/-   ##
=====================================================
  Coverage                 87.69%   87.69%           
=====================================================
  Files                       124      124           
  Lines                      2299     2299           
  Branches                    646      646           
=====================================================
  Hits                       2016     2016           
  Misses                      274      274           
  Partials                      9        9           

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@dcoa dcoa added the create-sandbox open-craft-grove should create a sandbox environment from this PR label Mar 18, 2025
@open-craft-grove
Copy link

Sandbox deployment failed 💥
Please check the settings and requirements.
Retry deployment by pushing a new commit or updating the requirements/settings in the pull request's description.
📜 Failure Logs
ℹ️ Grove Config, Tutor Config, Tutor Requirements

@dcoa dcoa marked this pull request as ready for review March 18, 2025 20:54
@dcoa dcoa requested a review from brian-smith-tcril March 18, 2025 20:55
@open-craft-grove
Copy link

Sandbox deployment successful 🚀
🎓 LMS
📝 Studio
ℹ️ Grove Config, Tutor Config, Tutor Requirements

@dcoa
Copy link
Contributor Author

dcoa commented Mar 19, 2025

The styles are not been displayed due to the url is not correct as you can see in the error:

The stylesheet https://app.pr-1436-1ec6b4.sandboxes.opencraft.hosting/authn/app.pr-1436-1ec6b4.sandboxes.opencraft.hosting/authn/paragon-theme-core.6f6c779f694ae379b95d.css was not loaded because its MIME type, “text/html”, is not “text/css”.

This is because frontend-platform uses BASE_URL to create the url, as you can see here

export const fallbackThemeUrl = (url) => {
  const baseUrl = getConfig().BASE_URL || window.location?.origin;
  return `${baseUrl}${basename}${url}`;
};

Problem

The problem is the url does not have the protocol on it, so is resolve as a path instead of a full url, is being defined by tutor-mfe like:

MFE_CONFIG = {
    "BASE_URL": "{{ MFE_HOST }}",
}

There is 2 ways to solve it:

  1. Update the tutor-mfe patches to handle the protocol
  2. Validate in frontend-platform if the variable has the protocol or not and add it if needed.

For the second point we might add some consistency in the MFEs variables (for development) most of the apps has the protocol on it but some of them not (as shown here)

Checked (has the http on it):

  • frontend-app-account
  • frontend-app-authn
  • frontend-app-authoring
  • frontend-app-communications
  • frontend-app-discussions
  • frontend-app-gradebook
  • frontend-app-learner-dashboard
  • frontend-app-learner-record
  • frontend-app-learning
  • frontend-app-ora
  • frontend-app-ora-grading
  • frontend-app-profile
  • frontend-app-publisher
  • frontend-app-support-tools
  • frontend-template-application

I would like to have your opinion before making any change @brian-smith-tcril

@brian-smith-tcril
Copy link
Contributor

@dcoa I would worry that updating the tutor-mfe patches to handle the protocol could lead to unexpected side effects, so I'd lean towards addressing this in fallbackThemeUrl.

we might add some consistency in the MFEs variables (for development) most of the apps has the protocol on it but some of them not

I think ideally we'd be able to handle both, so example.com/my.css and http(s)://example.com/my.css would work.

@adamstankiewicz thoughts?

@adamstankiewicz
Copy link
Member

I agree this would ideally be handled within @edx/frontend-platform itself, as it could impact non-tutor MFEs as well. In the case where no protocol (http/https) exists on the fallbackThemeUrl, perhaps // could be prepended (protocol-relative URL, e.g. docs)?

Example:

<link rel="stylesheet" href="//cdn.jsdelivr.net/npm/@openedx/[email protected]/dist/light.css">

In this case, the URL would use the same protocol as the current page (i.e., https if the app is hosted on https, http if the app is hosted on http).

@dcoa dcoa force-pushed the dcoa/design-tokens-support branch from 8c93fa5 to ad38966 Compare March 21, 2025 20:50
@open-craft-grove
Copy link

Sandbox deployment successful 🚀
🎓 LMS
📝 Studio
ℹ️ Grove Config, Tutor Config, Tutor Requirements

@dcoa
Copy link
Contributor Author

dcoa commented Mar 21, 2025

@brian-smith-tcril, this PR is ready for review ☺️

@dcoa dcoa force-pushed the dcoa/design-tokens-support branch from ad38966 to 4b48b92 Compare March 26, 2025 00:32
@open-craft-grove
Copy link

Sandbox deployment successful 🚀
🎓 LMS
📝 Studio
ℹ️ Grove Config, Tutor Config, Tutor Requirements

@dcoa dcoa force-pushed the dcoa/design-tokens-support branch from 4b48b92 to e6940e5 Compare March 31, 2025 00:10
@dcoa dcoa changed the title [WIP] feat: support design tokens and paragon 23 feat: support design tokens and paragon 23 Mar 31, 2025
@open-craft-grove
Copy link

Sandbox deployment successful 🚀
🎓 LMS
📝 Studio
ℹ️ Grove Config, Tutor Config, Tutor Requirements

@dcoa dcoa force-pushed the dcoa/design-tokens-support branch from e6940e5 to 856ee5c Compare April 11, 2025 04:11
@open-craft-grove
Copy link

Sandbox deployment successful 🚀
🎓 LMS
📝 Studio
ℹ️ Grove Config, Tutor Config, Tutor Requirements

@dcoa dcoa force-pushed the dcoa/design-tokens-support branch from 856ee5c to 5f03a07 Compare April 13, 2025 21:43
@open-craft-grove
Copy link

Sandbox deployment failed 💥
Please check the settings and requirements.
Retry deployment by pushing a new commit or updating the requirements/settings in the pull request's description.
📜 Failure Logs
ℹ️ Grove Config, Tutor Config, Tutor Requirements

@open-craft-grove
Copy link

Sandbox deployment successful 🚀
🎓 LMS
📝 Studio
ℹ️ Grove Config, Tutor Config, Tutor Requirements

@dcoa dcoa force-pushed the dcoa/design-tokens-support branch from 5f03a07 to 3ad941e Compare April 22, 2025 05:30
@open-craft-grove
Copy link

Sandbox deployment successful 🚀
🎓 LMS
📝 Studio
ℹ️ Grove Config, Tutor Config, Tutor Requirements

@dcoa dcoa force-pushed the dcoa/design-tokens-support branch from 3ad941e to d0417af Compare May 5, 2025 00:05
@open-craft-grove
Copy link

Sandbox deployment successful 🚀
🎓 LMS
📝 Studio
ℹ️ Grove Config, Tutor Config, Tutor Requirements

Copy link
Contributor

@brian-smith-tcril brian-smith-tcril left a comment

Choose a reason for hiding this comment

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

Overall this is looking wonderful! I left a couple comments with questions about moving away from using utility classes, but other than that this is looking very close to ready to merge!

@@ -40,7 +40,7 @@ $elevation-level-2-shadow: 0 0.125rem 0.25rem rgba(0, 0, 0, 0.15);
}

.main-content {
@extend .pt-4;
padding-top: calc(var(--pgn-spacing-spacer-base) * 1.5) !important;
Copy link
Contributor

Choose a reason for hiding this comment

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

It looks like .pt-4 is still listed in css utilities on the docs site https://paragon-openedx.netlify.app/foundations/css-utilities/

Does continuing to use .pt-4 here break things?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I made it like that to avoid import the paragon code inside the scss and increase the file of the bundle, for example keeping the line and importing the utilities-only.scss , make the app.css file 200kB because it adds all the utility classes to the final file, meanwhile with the direct css the file is 17.9 kB.

When I did the changes I was wondering what could be the best approach, use the utilities scss, replace the variable or add the utility class via jsx.

Copy link
Contributor

Choose a reason for hiding this comment

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

Interesting. I poked at this a bit and even when trying to use @use instead of @import I'm getting 200kB app.css files.

I definitely want to avoid the extra 180+kB, maybe just adding comments mentioning this is copied from a utility class would be helpful? Something like

Suggested change
padding-top: calc(var(--pgn-spacing-spacer-base) * 1.5) !important;
// This was originally extending .pt-4, a bootstrap utility class
// The calculated value can be seen here https://paragon-openedx-v23.netlify.app/foundations/css-utilities/
// Including Paragon's utilities-only.scss increases the css bundle size by ~180kB,
// so this is copied in directly instead.
padding-top: calc(var(--pgn-spacing-spacer-base) * 1.5) !important;

It's also possible I'm overlooking a different solution.

@adamstankiewicz - do you have any ideas?

Copy link
Contributor

Choose a reason for hiding this comment

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

Copy link
Contributor

Choose a reason for hiding this comment

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

In the 2025-05-07 Paragon WG meeting @adamstankiewicz mentioned (approximate quote based on WG transcript)

Yeah, I know for what it's worth, there are some trade-offs of using that extend class name sort of approach as well. it includes the important when in some cases that shouldn't be there. So I don't think we want to encourage that extend pattern for what it's worth. just broadly I remember just over the years multiple instances of CSS I added that used it and then it caused a bunch of issues down the road pasting is probably fine for the time being.

We then agreed (approximate quote from me based on transcript)

All right, sounds good. We can copy paste without context.

To summarize:

  • Using @extend with bootstrap utility classes has trade-offs.
    • For example: sometimes doing so includes !important when we don't want it to.
  • Therefore
    • We should not encourage using @extend with bootstrap utility classes.
    • Replacing @extend with copy/pasted rules (as this line change is doing) is perfectly reasonable.
    • We do not need to provide context for the copy/pasted rules using comments.

@dcoa dcoa force-pushed the dcoa/design-tokens-support branch from d0417af to aa5a949 Compare May 7, 2025 03:57
@open-craft-grove
Copy link

Sandbox deployment successful 🚀
🎓 LMS
📝 Studio
ℹ️ Grove Config, Tutor Config, Tutor Requirements

Copy link
Contributor

@brian-smith-tcril brian-smith-tcril left a comment

Choose a reason for hiding this comment

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

Thank you so much for your patience as we thought through the implications of these changes!

@brian-smith-tcril brian-smith-tcril changed the base branch from master to master-design-tokens May 8, 2025 14:54
@brian-smith-tcril brian-smith-tcril merged commit 6fdcc9b into openedx:master-design-tokens May 8, 2025
6 checks passed
@github-project-automation github-project-automation bot moved this from Waiting on Author to Done in Contributions May 8, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
create-sandbox open-craft-grove should create a sandbox environment from this PR open-source-contribution PR author is not from Axim or 2U
Projects
Archived in project
Development

Successfully merging this pull request may close these issues.

5 participants