dom-expressions: element.ownerDocument.documentElement is null onMount in linked package

With the following snippet:

export const BugCheck =  () => {
  const [documentElement, setDocumentElement] = createSignal<HTMLElement>()
  return (
    <pre
      ref={element => {
        onMount(() => setDocumentElement(element.ownerDocument.documentElement))
      }}
    >
      {documentElement() === null ? 'NULL' : documentElement()?.innerHTML}
    </pre>
  )
}

We get different results in between dev and build when linking the package into a solid app:

Screenshot 2024-10-26 at 15 47 15

element.ownerDocument.documentElement is defined in dev mode, but is null when build.

When delaying it by a frame with requestAnimationFrame we do get the expected result:

Screenshot 2024-10-26 at 15 53 41

When inlining it directly in the app, it also does not give an error, so it’s a quite surprising bug. Afaik the bug also does not seem to show up when downloading the published library, only during linking (am i correct in this, @ralphsmith80 ?)

a minimal reproduction of the bug

This bug came apparent during development of solid-plotly.js as plotly-js apparently makes use of this during initialisation.

About this issue

  • Original URL
  • State: open
  • Created 2 years ago
  • Reactions: 2
  • Comments: 19 (12 by maintainers)

Most upvoted comments

“@ralphsmith80/solid-plotly.js”: “link:…/solid-plotly.js/packages/solid-plotly.js”

Right, I just used pnpm link, but manually updated the package.json and it missed that.

If that’s the issue so be it. I only used linking like this because I was trying to test the library more thoroughly before publishing it. Not because that’s how I would build the production app that uses the library. In the end I published it and just crossed my fingers which worked.

Since it worked in the context of a mono-repo using linking, but no outside the context of a monorepo I didn’t catch why there would be a difference, but if there are in fact two instances of solid.js in that case then it makes sense why that would happen.

Seems like app is using solid-js from app/node_modules/solid-js and “lib” from lib/node_modules/solid-js

It has been commented in the linked thread that a “pnpm workspace” can be used to deal with this issue https://pnpm.io/workspaces

That’s correct @bigmistqke. It’s only an issue when linking.