Skip to content

Having issues getting example code to work as expected #36

@simonsteer

Description

@simonsteer

Hello 👋 I'm trying to play around with the polyfill and am struggling to get the example paint module to work as expected. Hoping to get some clarity on where I'm going awry setting things up.

The site I'm working on is built with Remix, which is server-side rendered, so I can't get access to the window until after the initial mount. The way I've gotten around this is by using isomorphicLayoutEffect and node require to load in the polyfill prior to calling CSS.paintWorklet.addModule.

import { useIsomorphicLayoutEffect } from 'react-use'

export default function Index() {
  useIsomorphicLayoutEffect(() => {
    require('css-paint-polyfill')
    CSS.paintWorklet.addModule('worklets/paint/box')
  }, [])

  return (
    <div>
      <h1>Testing Houdini Polyfill</h1>
      <div
        style={{
          width: 500,
          height: 400,
          background: 'paint(box)',
          border: '1px solid blue',
        }}
      />
    </div>
  )
}

This seems to work fine; the network request fetching the module code succeeds:

Screen Shot 2023-03-03 at 12 50 45 PM

The custom elements are being injected after the document body:

Screen Shot 2023-03-03 at 1 18 26 PM

And inline styles are being walked after paint registration:

Screen Shot 2023-03-03 at 1 19 22 PM

However, the custom paint does not seem to apply to the div; it just renders as a rectangle with a blue border, as though I had never applied the custom paint style:

Screen Shot 2023-03-03 at 1 23 18 PM

I'm assuming there's something funky going on when it comes to writing the paint css rules to a stylesheet, but not entirely sure.

Browsers I've tested this locally on:

  • Safari 15.5 (17613.2.7.1.8)
  • Firefox 110.0.1 (64-bit)
  • Chrome 110.0.5481.177 (Official Build) (x86_64)

Minimal github repo where I can reproduce the issue:
https://github.com/simonsteer/remix-houdini-test

Thanks in advance to the contributors working on this awesome project! Very exciting stuff :)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions