oddbird / oddbird/css-anchor-positioning

[BUG] Polyfill doesn't handle Vite loading CSS files as JS

Open
#303 5 comments 1 reaction 0 assignees View on GitHub

Nobody has claimed this yet.

bug question
Dominant language
TypeScript
Stars
493
Forks
18
Avg merge
12h 37m
Merged PRs (30d)
5

Description

Describe the bug
Image

I'm trying to install a css-anchor-positiong polyfill into my application and open it in safari.

I have this line in my application.js

if (!("anchorName" in document.documentElement.style)) {
  const { default: polyfill } = await import('@oddbird/css-anchor-positioning/fn');

  polyfill({
    elements: undefined,
    excludeInlineStyles: false,
    useAnimationFrame: false,
  });
}

This error occurs. Any advice on how to properly address it?

InvalidMimeType: Error loading http://localhost:3000/vite-dev/entrypoints/application.css: expected content-type "text/css", got "text/javascript".
(anonymous function) — fetch.ts:39
o — @oddbird_css-anchor-positioning_fn.js:23

vite.config.mjs

import { defineConfig } from 'vite'
import ViteRails from 'vite-plugin-rails'
import path from 'path' // Import 'path' for path resolution

const env = process.env.RAILS_ENV || 'development'

export default defineConfig({
  plugins: [
    ViteRails({
      fullReload: {
        additionalPaths: [
          'config/routes.rb',
          'app/views/**/*',
          'app/controllers/**/*',
          'app/models/**/*'
        ]
      }
    })
  ],
  define: {
    'process.env.RAILS_ENV': JSON.stringify(env)
  },
  resolve: {
    alias: {
      '@': path.resolve(__dirname, 'app/javascript')
    }
  }
})

Browsers tested on
Safari Version 18.3.1 (20620.2.4.11.6)

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with the fetch.ts:39 stack-trace location and the Vite Rails setup shown in vite.config.mjs. Reproduce the Safari loading failure and trace why the CSS entrypoint is returned as JavaScript; done means the polyfill loads the stylesheet with the expected text/css content type.

Written by the indexing model from the issue text.

Assessment

Tech stack
css, javascript, rails, typescript, vite
Domain
frontend, tooling, web-dev
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
25/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.