-
-
Notifications
You must be signed in to change notification settings - Fork 11
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] Polyfill fails if a <link>
fails to load or returns non-CSS content
#255
Comments
It is, unfortunately, more complicated than I thought. I was unable to reproduce it in a simple Vite app. |
Debugging further: Vite with vite-ruby generates a link tag in the main template that looks like this: <link rel="stylesheet" href="/vite-dev/entrypoints/application.scss" data-turbo-track="reload" /> However, the content served by vite-dev is neither CSS nor SCSS, but JavaScript instead (for HMR), and looks somewhat like this: import { createHotContext as __vite__createHotContext } from "/vite-dev/@vite/client";import.meta.hot = __vite__createHotContext("/entrypoints/application.scss");import { updateStyle as __vite__updateStyle, removeStyle as __vite__removeStyle } from "/vite-dev/@vite/client"
const __vite__id = "/Users/konstantin/Workspace/good-beans/pinto/app/frontend/entrypoints/application.scss"
const __vite__css = "... ACTUAL CSS HERE ..."
__vite__updateStyle(__vite__id, __vite__css)
import.meta.hot.accept()
import.meta.hot.prune(() => __vite__removeStyle(__vite__id)) I assume this then gets added somewhere else so just a guard might help? Update: Just guarding against the lack of children (i.e. |
I have not managed to reproduce this without vite-ruby, but I did manage to do so with it and a basic Rails app, no Vue needed at all. Example repo: https://github.com/rkh/vite-rails-example Reproduce:
|
@rkh Thanks for the repo! Is I think one task is for the polyfill to better handle Also, I would expect the polyfill to not work well with HMR- it currently only is applied once- see #91. Does the polyfill still work as expected in the built app? |
Yes, sorry, also getting the 404, only checked that it was the same error trace. I only tested it on non-dynamic elements, so I assume it won't work in the built app, either (can confirm that for you if you want). Feel free to close this issue if it is out of scope for you. I ended up not using the polyfill at all. Off topic: What I ended up doing.Unfortunately, relative positioning of popovers behaves differently between Firefox/Safari on the one hand and Chrome on the other, and thus I needed two different ways to implement this: $avatar-size: 32px;
$offset-x: 0px;
$offset-y: 2px;
@supports (anchor-name: --example) {
.avatar {
anchor-name: v-bind(anchorName);
}
.dropdown {
left: unset;
bottom: unset;
top: calc(anchor(v-bind(anchorName) bottom) + size($offset-y));
right: calc(anchor(v-bind(anchorName) right) + size($offset-x));
}
}
@supports not (anchor-name: --example) {
.dropdown {
position: relative;
align-self: start;
left: unset;
bottom: unset;
top: unset;
right: unset;
transform: translate(calc(size($avatar-size + $offset-x) - 100%), size($avatar-size + $offset-y));
}
} |
@rkh I would be interested in hearing if the polyfill works in a built vite rails app. I would expect it to work if the css file is served as CSS- confirmation would help us narrow down where this is an issue. Thanks! |
The 404 issue can be reproduced in the demo app by adding |
I can confirm the following for @oddbird/css-anchor-positioning 0.2.0 on Rails 7.1.4 with Vite 5.4.7:
Keep in mind that using Vite and Vue is not the standard Rails way. Instead the recommended approach is using Hotwire. This can result in HTML elements sometimes being dynamically added, and sometimes being included in the original HTML/CSS, so I'd suspect the polyfill would be unreliable in that scenario. |
<link>
fails to load or returns non-CSS content
This is released in v0.3.0. |
Great work on the polyfill! Haven't gotten it working yet, but hopefully I'll manage to.
Describe the bug
It is impossible for me to apply the polyfill. Getting the same error (different stack trace depending on the method used) when applying via Vite in dev mode, Vite bundle, or loading from unpkg (not my preference, as I don't want to add that to the CSP for production).
Example stacktrace:
This happens no matter if I load the Polyfill before or after initializing the rest of the app, no matter if any CSS rules actually specify any anchor properties.
The line numbers seem to be a little off (possibly a sourcemap issue?). I assume the line in question is line 72.
FYI the example page is working for me.
To Reproduce
It's a fairly complex app; I'll look into creating an example repo in the coming days, but I wanted to see if, maybe, from the stack trace, this is already something you can spot.
Code I'm using:
Example I'm trying to get working:
Expected behavior
Polyfill to be applied.
Screenshots
Firefox:
![image](https://private-user-images.githubusercontent.com/30442/373375548-6a2a3ede-7784-49ba-b551-aa9741f3dc61.png?jwt=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJnaXRodWIuY29tIiwiYXVkIjoicmF3LmdpdGh1YnVzZXJjb250ZW50LmNvbSIsImtleSI6ImtleTUi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BbXotRXhwaXJlcz0zMDAmWC1BbXotU2lnbmF0dXJlPTQxMWEyZjhmZWQxN2FmNWNmM2FhYTFiMGUzNWFiZjBiNTJkYmZiMTY2MDdiZjgwYmJmYWQ3MmNjMDM5YjhmN2UmWC1BbXotU2lnbmVkSGVhZGVycz1ob3N0In0.3XoTNsTowZWkfA-CnvSr8bXwMiaDDJvmgaVzkVX6wvU)
Browsers tested on
Firefox 130, Safari 18.1
The text was updated successfully, but these errors were encountered: