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

[bug] Styles don't get bundled #3427

Closed
Verzach3 opened this issue Feb 12, 2022 · 19 comments
Closed

[bug] Styles don't get bundled #3427

Verzach3 opened this issue Feb 12, 2022 · 19 comments

Comments

@Verzach3
Copy link

Describe the bug

when i run tauri dev the styles work normally, but when i do tauri build the styles are not added to the bundle

With tauri dev

image

With tauri build

image

Reproduction

  1. Create new project with create-tauri-app, select Typescript
  2. Add @fluentui/react with yarn add @fluentui/react
  3. Add a button from fluentui, i added PrimaryButton and DefaultButton
  4. run cargo tauri dev and the styles load
  5. run cargo tauri build and the components appear without styles

Expected behavior

No response

Platform and versions

Operating System - Windows, version 10.0.22000 X64
Webview2 - 98.0.1108.43
Visual Studio Build Tools:
   - Visual Studio Build Tools 2019

Node.js environment
  Node.js - 16.14.0
  @tauri-apps/cli - 1.0.0-rc.0
  @tauri-apps/api - 1.0.0-rc.0

Global packages
  npm - 8.3.1
  pnpm - Not installed
  yarn - 1.22.17

Rust environment
  rustc - 1.58.1
  cargo - 1.58.0

Rust environment
  rustup - 1.24.3
  rustc - 1.58.1
  cargo - 1.58.0
  toolchain - stable-x86_64-pc-windows-msvc

App directory structure
/.git
/build
/node_modules
/public
/src
/src-tauri

App
  tauri.rs - 1.0.0-rc.1
  build-type - bundle
  CSP - default-src 'self'
  distDir - ../build
  devPath - http://localhost:3000/
  framework - React

Note: It says Windows 10 but is Windows 11

Stack trace

No response

Additional context

No response

@Verzach3 Verzach3 changed the title Styles don't get bundled [bug] [bug] Styles don't get bundled Feb 12, 2022
@kt215
Copy link

kt215 commented Feb 12, 2022

I have the same exact issue with angular.

@nothingismagick
Copy link
Sponsor Member

Can one of you share your tauri.conf file?

@kt215
Copy link

kt215 commented Feb 12, 2022

In my case it's the default config created by npx create-tauri-app:

{
  "package": {
    "productName": "ngtest2",
    "version": "0.1.0"
  },
  "build": {
    "distDir": "../dist/ngtest2",
    "devPath": "http://localhost:4200",
    "beforeDevCommand": "npm run start",
    "beforeBuildCommand": "npm run build"
  },
  "tauri": {
    "bundle": {
      "active": true,
      "targets": "all",
      "identifier": "com.tauri.dev",
      "icon": [
        "icons/32x32.png",
        "icons/128x128.png",
        "icons/128x128@2x.png",
        "icons/icon.icns",
        "icons/icon.ico"
      ],
      "resources": [],
      "externalBin": [],
      "copyright": "",
      "category": "DeveloperTool",
      "shortDescription": "",
      "longDescription": "",
      "deb": {
        "depends": [],
        "useBootstrapper": false
      },
      "macOS": {
        "frameworks": [],
        "minimumSystemVersion": "",
        "useBootstrapper": false,
        "exceptionDomain": "",
        "signingIdentity": null,
        "providerShortName": null,
        "entitlements": null
      },
      "windows": {
        "certificateThumbprint": null,
        "digestAlgorithm": "sha256",
        "timestampUrl": ""
      }
    },
    "updater": {
      "active": false
    },
    "allowlist": {
      "all": true
    },
    "windows": [
      {
        "title": "Angular Test 2",
        "width": 800,
        "height": 600,
        "resizable": true,
        "fullscreen": false
      }
    ],
    "security": {
      "csp": "default-src 'self'"
    }
  }
}

@Verzach3
Copy link
Author

This is mine

{
  "package": {
    "productName": "raffle-manager-tauri-react",
    "version": "0.1.0"
  },
  "build": {
    "distDir": "../build",
    "devPath": "http://localhost:3000",
    "beforeDevCommand": "yarn start",
    "beforeBuildCommand": "yarn build"
  },
  "tauri": {
    "bundle": {
      "active": true,
      "targets": "all",
      "identifier": "com.gaer.rafflemanager",
      "icon": [
        "icons/32x32.png",
        "icons/128x128.png",
        "icons/128x128@2x.png",
        "icons/icon.icns",
        "icons/icon.ico"
      ],
      "resources": ["external/assets/"],
      "externalBin": [
        "external/binaries/raffle-editor",
        "external/binaries/list-dir"
      ],
      "copyright": "",
      "category": "DeveloperTool",
      "shortDescription": "",
      "longDescription": "",
      "deb": {
        "depends": [],
        "useBootstrapper": false
      },
      "macOS": {
        "frameworks": [],
        "minimumSystemVersion": "",
        "useBootstrapper": false,
        "exceptionDomain": "",
        "signingIdentity": null,
        "providerShortName": null,
        "entitlements": null
      },
      "windows": {
        "certificateThumbprint": null,
        "digestAlgorithm": "sha256",
        "timestampUrl": ""
      }
    },
    "updater": {
      "active": false
    },
    "allowlist": {
      "all": true,
      "shell": {
        "all": true,
        "execute": true,
        "open": false,
        "scope": [
          {
            "name": "external/binaries/raffle-editor",
            "cmd": "raffle-editor",
            "sidecar": true,
            "args": true
          }
        ],
        "sidecar": true
      }
    },
    "windows": [
      {
        "title": "Raffle Manager",
        "width": 800,
        "height": 600,
        "resizable": true,
        "fullscreen": false
      }
    ],
    "security": {
      "csp": "default-src 'self' "
    }
  }
}

@nothingismagick
Copy link
Sponsor Member

Are there any warnings in the log during tauri build

@nothingismagick
Copy link
Sponsor Member

And does this happen if you run tauri build --debug? If it does, then please check the console tab under sources and let us know what you find there

@lucasfernog
Copy link
Member

The styles should exist on the distDir folder. Maybe angular is not configured to do so, and it stays on the public directory? i'm not at home right now but i can check this tomorrow.

@kt215
Copy link

kt215 commented Feb 12, 2022

tauri build and angular worked just fine with the last beta version (8?). No warning with tauri build or tauri build --debug. It only works correctly with latest using tauri dev:
image

@kt215
Copy link

kt215 commented Feb 12, 2022

With tauri build and AppImage on Linux Mint. It shows a "blank" page, then scroll down and you see this:
image

@lucasfernog
Copy link
Member

Did you guys check the console for errors? it might also be a CSP error, so you can try setting the csp to null on tauri.conf.json

@kt215
Copy link

kt215 commented Feb 13, 2022

Setting csp: null appears to have fixed it for me.

@Verzach3
Copy link
Author

I have the same behavior as kt215, there are no warnings and it only works with tauri dev, by the way setting csp to null solves the problem, does leaving csp to null have any inconvenience?

@lucasfernog
Copy link
Member

The content security policy is a nice security feature but it needs configuration from your side, like allowing accessing remote fonts and stylesheets, so that might be the issue here. For now I'll change the default template to disable CSP so new users don't need to face this, but our documentation still encourage you to implement CSP for your app as that secures you from untrusted content loading.

@dolsem
Copy link

dolsem commented May 19, 2022

@lucasfernog I am using the @suid/material library and I'm having the same issue with my styles. My CSP is set to "default-src 'self'; img-src 'self' asset: https://asset.localhost". I checked the network tab in development and both XHR and CSS tabs are empty. If I set CSP to null though, it works. Any idea what could be wrong?

@lucasfernog
Copy link
Member

@dolsem I can take a look if you can share a repo to reproduce it.

@dolsem
Copy link

dolsem commented May 19, 2022

@lucasfernog
Copy link
Member

Suid has dynamic styles, I'll see if there's a way around it.

@lucasfernog
Copy link
Member

@dolsem not much we can do here since @suid/material dynamically adds style tags so you'd need to disable the style-src modification from Tauri https://tauri.studio/v1/api/config#securityconfig.dangerousdisableassetcspmodification

@jsanta
Copy link

jsanta commented May 1, 2023

Might be resurrecting a zombie here. I recently faced the same problem.
Happens that my Angular build inlined the critical styles. Inlined styles are "nonced" by Tauri build (by the way tauri dev is not affected by this behavior).

Solved it by setting the production build setting on my angular project to:

"production": {
     // other settings
      "optimization": {
        "scripts": true,
        "styles": {
          "minify": true,
          "inlineCritical": false
        },
        "fonts": false
      }
    }

More on this here: https://0xdbe.github.io/AngularSecurity-DisableInlineCriticalCSS/

Followed Angular's recommendation on a minimal CSP setting, and adjusted it to my needs to something like:

default-src 'self'; style-src 'self' 'unsafe-inline'; img-src 'self' data:; object-src 'none'; require-trusted-types-for 'script';

Would be nice to have a Tauri setting in order to be able to dynamically configure an allowed nonce, acording to the TAURI_SCRIPT_NONCE and TAURI_STYLE_NONCE . Didn't find if it's possible to override Tauri's generated values, or place a placeholder in the configuration in order to allow the generated on compilation nonce values.

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

No branches or pull requests

6 participants