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

Lazy evaluate head styles #2374

Closed
vidhu opened this issue Oct 17, 2021 · 3 comments
Closed

Lazy evaluate head styles #2374

vidhu opened this issue Oct 17, 2021 · 3 comments

Comments

@vidhu
Copy link
Contributor

vidhu commented Oct 17, 2021

Is your feature request related to a problem? Please describe

I have a custom head component which emits Heading styles. It also emits heading styles in a media query i.e

add('style', `
  h1 {
    font-size: 26px;
  }

  @media only screen and (max-width:480px) {
    h1 {
      font-size: 20px;
    }
  }
`)

The issue is I need to hardcode the breakpoint. If the breakpoint is changed using a <mj-breakpoint/> component, then this would not work as expected.

Describe the solution you'd like

I propose (and happy to submit a PR) to allow adding a function to the list of styles add('style', (breakpoint) => string) which would be executed in the skeleton. This would allow lazy evaluation of any styles and use the globalDatas as a context.

To solve the above use case with this new change, the code would look like

add('style', (breakpoint) => `
  h1 {
    font-size: 26px;
  }

  @media only screen and (max-width:${breakpoint}) {
    h1 {
      font-size: 20px;
    }
  }
`)

During execution, this would mean all the head components including the breakpoint has been evaluated before this style is "lazy evaluated" in the skeleton

Again, I'm happy to submit a PR as a PoC and continue on it if you like the proposal.

Describe alternatives you've considered
I dont see any other alternative to emitting styles from a head component and taking the breakpoint into account

@vidhu vidhu changed the title Lazy Evaluate head styles Lazy evaluate head styles Oct 17, 2021
@iRyusa
Copy link
Member

iRyusa commented Oct 18, 2021

Hi @vidhu !

That would be really cool to have something like this ! As globalDatas (we really need to rename that var 😬) can be altered during mj-head processing, it totally need lazy evaluation for this 👍

@vidhu
Copy link
Contributor Author

vidhu commented Oct 18, 2021

@iRyusa Thanks for the go ahead. I opened a PR. Let me know what you think

@kmcb777
Copy link
Collaborator

kmcb777 commented Nov 24, 2021

the PR has been merged and released so we can close this one

@kmcb777 kmcb777 closed this as completed Nov 24, 2021
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

No branches or pull requests

3 participants