Skip to content

fix: grid template is parsed incorrectly by chrome #1396

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

Closed
wants to merge 3 commits into from
Closed

fix: grid template is parsed incorrectly by chrome #1396

wants to merge 3 commits into from

Conversation

pauldambra
Copy link
Contributor

fixes: #1395

Chrome is not correctly providing cssText when the style includes a grid-template-area rule. This PR attempts to detect and correct this...

(it's my first PR against the repo, so have opened early to get feedback and guidance :))

Copy link

changeset-bot bot commented Jan 10, 2024

🦋 Changeset detected

Latest commit: 7bede51

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 8 packages
Name Type
rrweb-snapshot Patch
rrweb Patch
rrdom Patch
rrdom-nodejs Patch
rrweb-player Patch
@rrweb/types Patch
@rrweb/web-extension Patch
rrvideo Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@jaj1014
Copy link

jaj1014 commented Jan 25, 2024

Came across this PR and it's one I've seen, too and wanted to add some additional detail to help illustrate the issue.

I put together a gist and debug video w/ a sample recording that demonstrates the issue.

For reference, this is what the layout should look like.

Screenshot 2024-01-25 at 5 24 14 AM

@eoghanmurray
Copy link
Contributor

If you add a changeset file (see changeset-bot comment on this page) it should re-trigger the tests.
(this PR was created without permissions for me to do this for you myself)

@pauldambra
Copy link
Contributor Author

(this PR was created without permissions for me to do this for you myself)

Ah, sorry. How do I create with permissions?

@eoghanmurray
Copy link
Contributor

In addition to the note above about the repeat() function in the tests, I'm wondering whether this is currently a bug in Chrome/Chromium or whether this PR is a fix for older versions of browsers?

@okejminja
Copy link
Contributor

In addition to the note above about the repeat() function in the tests, I'm wondering whether this is currently a bug in Chrome/Chromium or whether this PR is a fix for older versions of browsers?

https://issues.chromium.org/issues/40227336
I think it's a bug in Chromium

We omitted from using sheet.cssRules in our fork until that's resolved since that's when the bug shows

@eoghanmurray
Copy link
Contributor

Ah, sorry. How do I create with permissions?

There's a ' Allow edits and access to secrets by maintainers' checkbox in the rhs column

@eoghanmurray
Copy link
Contributor

You might have missed my review query;
"This doesn't appear to be valid grid-template syntax"

@pauldambra
Copy link
Contributor Author

You might have missed my review query;
"This doesn't appear to be valid grid-template syntax"

I did... in fact, I can't see it anywhere 🙈

This was quite a while ago so my brain has jettisoned all context 🤣

We've had a single user mention it, and they're not chasing us. So, I'm just as happy to get validation that the approach/files changed are about right (even if the actual implementation isn't desirable) and close the PR

documentNode,
documentTypeNode,
serializedNode,
serializedNodeWithId,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for your contribution!
Small note: reordering here will make it harder to merge in other in-progress PRs that might make changes in the same lines and makes it harder to review; looks like there are no changes?


it('fixes incorrectly parsed grid template rules', () => {
const cssText =
'#wrapper { display: grid; grid-template: "header header" max-content / repeat(2, 1fr); margin: 0px auto; }';
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This doesn't appear to be valid grid-template syntax

"Note: The repeat() function isn't allowed in these track listings, as the tracks are intended to visually line up one-to-one with the rows/columns in the "ASCII art"."
https://developer.mozilla.org/en-US/docs/Web/CSS/grid-template#values

'grid-template-areas:',
);
if (
isCSSStyleRule(rule) &&
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This isCSSStyleRule check has already been performed outside of the function call

@@ -125,7 +165,11 @@ export function stringifyRule(rule: CSSRule): string {
return fixSafariColons(rule.cssText);
}

return importStringified || rule.cssText;
if (isCSSStyleRule(rule)) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This check will be performed twice at this point; we create one } else if (isCSSStyleRule(rule)) { section and have this grid fix and the safari colons fix within it

Copy link
Contributor

@eoghanmurray eoghanmurray left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In case you missed the questions

@eoghanmurray
Copy link
Contributor

Also, do you recall whether the problem was manifesting in a <link rel="stylesheet"> context, or in a <style> element?
If the latter, we may be able to resolve it another way.

@pauldambra
Copy link
Contributor Author

I don't remember at all and we've not had further reports... since I captured a fiddle to demo the bug at reporting time I'll defer to #1458 and check if that fixes this

We can re-open this if need be then but let's not add code for an very rare case if we can avoid it :)

@pauldambra pauldambra closed this May 9, 2024
@eoghanmurray
Copy link
Contributor

OK there may be a new approach possible; see
#1357 (comment)

Basically we stringify .sheet.rules during a snapshot as if any programmatic modifications have taken place (rule inserts/deletions), then that will have them, whereas the raw text does not. So if we could verify that a 'normalized' .sheet.rules matches a normalized rawtext (not a simple task), then we could just go ahead and use the raw text.

A job for another day, but if you think you can salvage the tests out of this one (I mentioned some seemingly incorrect syntax) then we could commit that albeit commented out with a TODO until we can fix this.

@jaj1014
Copy link

jaj1014 commented Oct 21, 2024

I've opened a new PR that builds on the work from this one. We had been using the code from the closed PR, but hit an issue w/ the regex that was in the original work so I've updated to address that in the new one

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

Successfully merging this pull request may close these issues.

[Bug]: grid template areas are not inlined correctly by Chrome
4 participants