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

V5 Alert: Breaks SSR in Gatsby #33722

Closed
yshterev opened this issue Apr 22, 2021 · 2 comments
Closed

V5 Alert: Breaks SSR in Gatsby #33722

yshterev opened this issue Apr 22, 2021 · 2 comments

Comments

@yshterev
Copy link

yshterev commented Apr 22, 2021

Using bootstrap@^5.0.0-beta3 as ES6 modules in React/Gatsby.js

In node window and document are undefined. There should be a check for these so they work in similar cases.
https://github.com/twbs/bootstrap/blob/main/js/src/alert.js#L130

@yshterev yshterev changed the title V5 Alert: Breaks SSR V5 Alert: Breaks SSR in Gatsby Apr 22, 2021
@yshterev
Copy link
Author

Sorry, this can be fixed by conditional dynamic import. Don't think it is relevant to bootstrap.
In case someone needs it:

const bootstrap = typeof window !== `undefined` && import("bootstrap")

useEffect(() => {
    bootstrap?.then(({ Modal }) => {
      const modalEl = modalRef.current
      setModal(new Modal(modalEl, { keyboard: false, backdrop: "static" }))
    })
  }, [])

Seems to work.

@TCB13
Copy link

TCB13 commented Apr 13, 2023

Sorry, this can be fixed by conditional dynamic import. Don't think it is relevant to bootstrap.

We can't always depend on dynamic imports, this has everything to do with BS. Read this: #34989 (comment)

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