Skip to content

[Skeleton] Not rendered when Strict CSP is applied in Next.js #45682

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

Closed
kuanjiahong opened this issue Mar 26, 2025 · 2 comments
Closed

[Skeleton] Not rendered when Strict CSP is applied in Next.js #45682

kuanjiahong opened this issue Mar 26, 2025 · 2 comments
Labels
component: skeleton This is the name of the generic UI component, not the React module!

Comments

@kuanjiahong
Copy link

kuanjiahong commented Mar 26, 2025

Steps to reproduce

Steps:

  1. Open this link (https://codesandbox.io/p/github/kuanjiahong/mui-skeleton-not-rendered/main) to live example: (required).
  2. Open this link to view the preview by CodeSandbox (https://n4fhch-3000.csb.app/)
  3. Open this link to see the application when deployed to Vercel (https://mui-skeleton-not-rendered.vercel.app/)

Current behavior

Only one Skeleton component is shown on screen

Image

Expected behavior

Two Skeleton components should be shown on screen

Image

Context

I want to show loading skeleton for sidebar and header. However, when strict csp is applied, only one skeleton is shown. The configuration for strict csp is based on this link (https://nextjs.org/docs/app/building-your-application/configuring/content-security-policy)

However, there is a workaround to this issue which is to use unsafe-inline in style-src and not nonce-${nonce}. But this might not be best case since it might introduce to some security vulnerabilities to the application.

Your environment

npx @mui/envinfo
  Don't forget to mention which browser you used.
  Output from `npx @mui/envinfo` goes here.
  System:
    OS: Windows 10 10.0.19045
  Binaries:
    Node: 22.12.0 - C:\Program Files\nodejs\node.EXE
    npm: 11.0.0 - C:\Program Files\nodejs\npm.CMD   
    pnpm: Not Found
  Browsers:
    Chrome: Not Found
    Edge: Chromium (132.0.2957.115)
  npmPackages:
    @emotion/react: ^11.14.0 => 11.14.0
    @emotion/styled: ^11.14.0 => 11.14.0
    @mui/core-downloads-tracker:  6.4.8
    @mui/material: ^6.4.8 => 6.4.8
    @mui/material-nextjs: ^6.4.3 => 6.4.3
    @mui/private-theming:  6.4.8
    @mui/styled-engine:  6.4.8
    @mui/system:  6.4.8
    @mui/types:  7.2.24
    @mui/utils:  6.4.8
    @types/react: ^19 => 19.0.12
    react: ^19.0.0 => 19.0.0
    react-dom: ^19.0.0 => 19.0.0
    typescript: ^5 => 5.8.2

Search keywords: nextjs, strict-csp, content-security-policy, css, unsafe-inline, nonce, skeleton

@kuanjiahong kuanjiahong added the status: waiting for maintainer These issues haven't been looked at yet by a maintainer label Mar 26, 2025
@aarongarciah aarongarciah changed the title [skeleton] Skeleton not rendered when Strict CSP is applied in Next.js [Skeleton] Not rendered when Strict CSP is applied in Next.js Mar 26, 2025
@aarongarciah aarongarciah added the component: skeleton This is the name of the generic UI component, not the React module! label Mar 26, 2025
@aarongarciah
Copy link
Member

@kuanjiahong using the sx prop removes the need for inline style. Instead of passing width and height as props, pass them in the sx prop.

<Skeleton
  sx={{
    display: { xs: "none", md: "block" },
+   width: 210,
+   height: "100vh"
  }}
  variant="rectangular"
- width={210}
- height="100vh"
/>

PS: there's a bug in the code: display: auto is not valid.

Copy link

This issue has been closed. If you have a similar problem but not exactly the same, please open a new issue.
Now, if you have additional information related to this issue or things that could help future readers, feel free to leave a comment.

@github-actions github-actions bot removed the status: waiting for maintainer These issues haven't been looked at yet by a maintainer label Mar 26, 2025
kuanjiahong referenced this issue in kuanjiahong/mui-skeleton-not-rendered Mar 28, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
component: skeleton This is the name of the generic UI component, not the React module!
Projects
None yet
Development

No branches or pull requests

2 participants