Skip to content
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

HTMLButtonElement is not defined on svelte-kit SSR #94

Closed
jangxyz opened this issue May 16, 2022 · 2 comments
Closed

HTMLButtonElement is not defined on svelte-kit SSR #94

jangxyz opened this issue May 16, 2022 · 2 comments

Comments

@jangxyz
Copy link

jangxyz commented May 16, 2022

Describe the bug
When using the Tabs component, I get a ReferenceError: HTMLButtonElement is not defined error.
This happens when the two conditions meet:

  1. Set Tab#as prop to something besides "button".
  2. Renders the page in SvelteKit ssr mode.

Setting ssr: false in hooks.js (see svelte-kit doc on hooks) can avoid this problem, but there should be a fundamental solution.

Seems like HTMLButtonElement is not defined in ssr mode, and the code is only reached if as is not "button" (default value):

export function resolveButtonType(
props: { type?: string; as?: SupportedAs },
ref: HTMLElement | null | undefined
): string | undefined {
if (props.type) return props.type;
let tag = props.as ?? "button";
if (typeof tag === "string" && tag.toLowerCase() === "button")
return "button";
if (ref instanceof HTMLButtonElement) return "button";
return undefined;
}

To Reproduce

Here's a repo with a fresh svelte-kit starter with basic Tabs demo. (index.svelte#L8-19)

<TabGroup>
  <TabList>
    <Tab as="div">Tab 1</Tab>
    <Tab as="div">Tab 2</Tab>
    <Tab as="div">Tab 3</Tab>
  </TabList>
  <TabPanels>
    <TabPanel>Content 1</TabPanel>
    <TabPanel>Content 2</TabPanel>
    <TabPanel>Content 3</TabPanel>
  </TabPanels>
</TabGroup>

Library version

Using [email protected]

@jangxyz jangxyz changed the title `HTMLButtonElement is not defined on svelte-kit SSR HTMLButtonElement is not defined on svelte-kit SSR May 16, 2022
@rgossiaux
Copy link
Owner

Ah interesting, thanks for the great report! Sorry you ran into this. I just published a fix as 1.0.1 on npm.

jangxyz added a commit to jangxyz/svelte-headlessui-button-error that referenced this issue May 16, 2022
@jangxyz
Copy link
Author

jangxyz commented May 16, 2022

Confirmed :D
What a simple fix! Thanks!

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

No branches or pull requests

2 participants