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

regression: inlined css @font-face src url crashes Vite 2.9.7 and above #8091

Closed
7 tasks done
laurentpayot opened this issue May 10, 2022 · 0 comments · Fixed by #8094
Closed
7 tasks done

regression: inlined css @font-face src url crashes Vite 2.9.7 and above #8091

laurentpayot opened this issue May 10, 2022 · 0 comments · Fixed by #8094
Labels
feat: css p3-minor-bug An edge case that only affects very specific usage (priority) regression The issue only appears after a new release

Comments

@laurentpayot
Copy link
Contributor

Describe the bug

In my head section of index.html if I put the following style:

    <style>
      /* latin */
      @font-face {
        font-family: 'Roboto';
        font-style: normal;
        font-weight: 400;
        font-display: fallback;
        src:
          local('Roboto'),
          local('Roboto-Regular'),
          url(https://fonts.gstatic.com/s/roboto/v29/KFOmCnqEu92Fr1Mu4mxK.woff2) format('woff2');
        unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6, U+02DA, U+02DC, U+2000-206F, U+2074, U+20AC, U+2122, U+2191, U+2193, U+2212, U+2215, U+FEFF, U+FFFD;
      }
      body {
        font-family: Roboto, sans-serif;
        background-color: green;
      }
    </style>

When the dev server is running and a browser opens the page, I get:

[vite] Internal server error: Failed to parse source for import analysis because the content contains invalid JS syntax. You may need to install appropriate plugins to handle the .css file format.
  Plugin: vite:import-analysis
  File: /home/laurent/projects/SSCCE/vite-font-face-src-url-issue/index.html?html-proxy&index=0.css
  1  |  
     |  ^
  2  |        /* latin */
  3  |        @font-face {
      at formatError (/home/laurent/projects/SSCCE/vite-font-face-src-url-issue/node_modules/vite/dist/node/chunks/dep-e1fc1d62.js:38724:46)
      at TransformContext.error (/home/laurent/projects/SSCCE/vite-font-face-src-url-issue/node_modules/vite/dist/node/chunks/dep-e1fc1d62.js:38720:19)
      at TransformContext.transform (/home/laurent/projects/SSCCE/vite-font-face-src-url-issue/node_modules/vite/dist/node/chunks/dep-e1fc1d62.js:56837:22)
      at async Object.transform (/home/laurent/projects/SSCCE/vite-font-face-src-url-issue/node_modules/vite/dist/node/chunks/dep-e1fc1d62.js:38961:30)
      at async /home/laurent/projects/SSCCE/vite-font-face-src-url-issue/node_modules/vite/dist/node/chunks/dep-e1fc1d62.js:56316:24
      at async Promise.all (index 0)
      at async devHtmlHook (/home/laurent/projects/SSCCE/vite-font-face-src-url-issue/node_modules/vite/dist/node/chunks/dep-e1fc1d62.js:56311:5)
      at async applyHtmlTransforms (/home/laurent/projects/SSCCE/vite-font-face-src-url-issue/node_modules/vite/dist/node/chunks/dep-e1fc1d62.js:29511:21)
      at async viteIndexHtmlMiddleware (/home/laurent/projects/SSCCE/vite-font-face-src-url-issue/node_modules/vite/dist/node/chunks/dep-e1fc1d62.js:56347:28)

The build is working, and the preview too.
It was working fine with Vite 2.9.6. It’s not working with versions 2.9.7 and above.

The culprit is the following line:

url(https://fonts.gstatic.com/s/roboto/v29/KFOmCnqEu92Fr1Mu4mxK.woff2) format('woff2');

If you remove this line, it works.
Could this be an issue about inlined css urls?

Reproduction

https://stackblitz.com/edit/vitejs-vite-pusvkz?file=index.html

System Info

System:
    OS: Linux 5.15 Ubuntu 22.04 LTS 22.04 LTS (Jammy Jellyfish)
    CPU: (8) x64 AMD FX(tm)-8350 Eight-Core Processor
    Memory: 17.38 GB / 31.31 GB
    Container: Yes
    Shell: 5.1.16 - /bin/bash
  Binaries:
    Node: 17.6.0 - ~/.nvm/versions/node/v17.6.0/bin/node
    npm: 8.5.1 - ~/.nvm/versions/node/v17.6.0/bin/npm
  Browsers:
    Chrome: 101.0.4951.54
    Chromium: 101.0.4951.54
    Firefox: 100.0
  npmPackages:
    vite: ^2.9.8 => 2.9.8

Used Package Manager

npm

Logs

No response

Validations

@sapphi-red sapphi-red added feat: css regression The issue only appears after a new release p2-edge-case Bug, but has workaround or limited in scope (priority) p3-minor-bug An edge case that only affects very specific usage (priority) and removed pending triage p2-edge-case Bug, but has workaround or limited in scope (priority) labels May 10, 2022
@github-actions github-actions bot locked and limited conversation to collaborators May 26, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
feat: css p3-minor-bug An edge case that only affects very specific usage (priority) regression The issue only appears after a new release
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants