LWC CSS file deployment error

Issue #2169 resolved
Adam Stepanek created an issue

Hi Scott,

when you create a new lwc CSS file, it gets immediately deployed, which results in an error stating that the file cannot be empty.

ERROR deploying LightningComponentBundle lwc/multiComboboxFSC/multiComboboxFSC.js-meta.xml: Lightning Component Resource [lwc/multiComboboxFSC/multiComboboxFSC.css] for Lightning Component Bundle multiComboboxFSC cannot be empty.

repro steps:

  1. have lwc cmp with js and html file.
  2. right click inside the bundle and select new css file

Comments (6)

  1. Scott Wells repo owner

    I'm not able to reproduce this. I do this pretty frequently and have never seen it in the past, but I just decided to try it again with the same result. Here's the corresponding debug log:

    2022-08-03 08:16:02,726 [61615721]   FINE - #c.i.i.b.ForceComBuilder - Checking whether this is a single item static resource or Lightning bundle file deployment using the Tooling API.
    2022-08-03 08:16:02,727 [61615722]   INFO - #c.i.i.b.ForceComBuilder - Deploying single LWC bundle file C:/Users/Scott/dev/projects/IlluminatedCloudTestProjects/df17-with-manifest/force-app/main/default/lwc/issue2169/issue2169.css using the Tooling API.
    2022-08-03 08:16:02,727 [61615722]   FINE - #c.i.i.b.ForceComBuilder - Creating a metadata package for module df17-with-manifest.
    2022-08-03 08:16:02,727 [61615722]   FINE - #c.i.i.b.ForceComBuilder -   Creating a metadata package based on package.xml file manifest/package.xml.
      "ignoreErrors": true,
    2022-08-03 08:16:02,741 [61615736]   FINE - #c.i.i.b.ForceComToolingApiDeployer - Deploying issue2169.css to demo
    2022-08-03 08:16:03,290 [61616285]   INFO - #c.i.i.b.ForceComToolingApiDeployer - Using the tooling API to create Lightning bundle file issue2169.css.
    2022-08-03 08:16:03,295 [61616290]   FINE - #c.i.i.b.ForceComToolingApiDeployer - Sending REST request body to https://ic-demo-dev-ed.my.salesforce.com/services/data/v55.0/tooling/sobjects/LightningComponentResource:
    {"filePath":"lwc/issue2169/issue2169.css","format":"CSS","lightningComponentBundleId":"0Rb2E0000000A0eSAE","source":"/**\n * Created by Scott on 8/3/2022.\n */\n"}
    2022-08-03 08:16:03,619 [61616614]   WARN - #c.i.o.a.i.ActionUpdater - 348 ms to grab EDT for #update@ToolwindowTitle (com.intellij.toolWindow.ToolWindowHeader$2)
    2022-08-03 08:16:05,342 [61618337]   INFO - #g.c.GitHandler - [df17-with-manifest] git -c core.quotepath=false -c log.showSignature=false add --ignore-errors -A -- force-app/main/default/lwc/issue2169/issue2169.css
    2022-08-03 08:16:05,696 [61618691]   FINE - #c.i.i.b.ForceComToolingApiDeployer - Received expected status code 201.
    2022-08-03 08:16:05,696 [61618691]   FINE - #c.i.i.b.ForceComToolingApiDeployer - Received creation response:
    {"id":"0Rd2E0000000U1kSAE","success":true,"errors":[],"warnings":[],"infos":[]}
    2022-08-03 08:16:05,698 [61618693]   FINE - #c.i.i.b.ForceComToolingApiDeployer - Deployed issue2169.css in 2969 ms.
    

    Can you please enable debug logging for metadata deployment, reproduce the issue, and attach the resulting idea.log for review?

  2. Adam Stepanek reporter

    Just a thought, the CSS file you get created is empty, without any comments? I remember that I’ve removed the auto-comments from the top of the file in the setup, so my file is getting created completely empty and that is the reason why it is failing.

    If I put a comment to the file, it gets deployed just ok.

  3. Scott Wells repo owner

    Ah, okay. Yes, that's why the default file template for that file includes the comment. Sorry, I didn't realize that you'd changed the file template to eliminate all contents. I guess I could not deploy an empty CSS file, though I generally try to avoid that kind of special-case logic. Is there a specific reason that the file template was modified to be empty?

  4. Adam Stepanek reporter

    I don’t remember exactly the content of the comment, but probably something about the creator of the file. We have recognized this as noise which can be eliminated as the information can be found in vcs. Those kinds of comments are antipattern to clean code. So we removed them from all files.

    I understand that deploying empty files is an edge scenario but not specific as sf will probably fail any empty file being deployed.

  5. Scott Wells repo owner

    Files created by IC2--at least those based on the bundled file templates--should be immediately ready for a successful deployment. As you point out, for the most part those files must have a body, typically one that conforms to the required syntax/schema of the associated file type. LWC CSS files are generated based on this file template:

    Issue_2169_LWC_CSS.png

    which by default just includes the corresponding header template:

    Issue_1269_LWC_CSS_Header.png

    It's the latter that's resulting in the comment. You can--and should--certainly edit that to be whatever makes sense for your organization, typically a copyright header (which the IDE can help maintain over time based on its own Copyright plugin), and you can even choose to remove all contents for any of these file templates you'd like, but that can result in deployment failures when deployed via IC2, the CLI, or a CI/CD system until actual contents are added.

    I'm not a fan of adding corner-case logic to skip deployment of a file with an empty body. Even with some type of notification--likely via a toaster saying something like "Skipping deployment of <filename> due to empty contents", my guess is that I'll end up fielding questions and/or logged bugs from that unexpected behavior. Probably not the desired response, but I think that it's consistent with any other tooling you'd find when a file is created that's not ripe for deployment.

    Oh, and if you try to view/edit those file templates and see a big green box, that appears to be a recent regression in the base JetBrains IDEs:

    https://youtrack.jetbrains.com/issue/IDEA-299563

    I'll have the workaround described in that issue included in this week's build (basically changing the line endings) and could provide access to that earlier if needed.

  6. Scott Wells repo owner

    I'm going to resolve this as working-as-defined based on the previous discussion. Certainly let me know if you strongly disagree.

  7. Log in to comment