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

[proposal] feat: Custom Stylesheet injection #476

Closed
wants to merge 1 commit into from

Conversation

Dhanielk
Copy link

@Dhanielk Dhanielk commented Jul 7, 2022

I think there were multiple requests like #371 to have ability to include custom stylesheets into head element of root html. I don't think we need full ability to override whole root template (like #380), but have ability to inject stylesheets would suffices.

With this approach we could only modify render function in main.ts to have stylesheets included on every page.

Example:

...
function render(ctx: RenderContext, render: InnerRenderFunction) {
  ...
  ctx.styleSheets.push(asset('/my.local.css'));
  ctx.styleSheets.push('https://my.remote/file.css'));
}

await start(manifest, { render });

I will leave the decision for this feature to you, but it would be enough for my needs to have this change rather than overriding whole root template.

@harrel56
Copy link
Contributor

harrel56 commented Jul 9, 2022

Isn't this issue solved by using _app.tsx in conjunction with Head component? Injecting style sheets here seems to work nicely, or am I missing something? Usage example taken from tests:

/** @jsx h */
/** @jsxFrag Fragment */
import { Fragment, h } from "preact";
import { Head } from "$fresh/runtime.ts";
import { AppProps } from "$fresh/server.ts";

export default function App(props: AppProps) {
  return (
    <>
      <Head>
        <meta name="description" content="Hello world!" />
      </Head>
      <props.Component />
    </>
  );
}

@Dhanielk
Copy link
Author

Dhanielk commented Jul 9, 2022

Isn't this issue solved by using _app.tsx in conjunction with Head component? Injecting style sheets here seems to work nicely, or am I missing something? Usage example taken from tests:

/** @jsx h */
/** @jsxFrag Fragment */
import { Fragment, h } from "preact";
import { Head } from "$fresh/runtime.ts";
import { AppProps } from "$fresh/server.ts";

export default function App(props: AppProps) {
  return (
    <>
      <Head>
        <meta name="description" content="Hello world!" />
      </Head>
      <props.Component />
    </>
  );
}

That is actually true! I haven't found it anywhere (I might have missed it in documentation) and it seems the others missed it as well. Thanks a lot for input, I will close this PR then.

@Dhanielk Dhanielk closed this Jul 9, 2022
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.

2 participants