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

Deferred run #2067

Closed
wants to merge 2 commits into from
Closed

Conversation

DarthSim
Copy link

Summary

On the imgproxy docs site, we need to fetch imgproxy versions to configure Docsify. Since we need to send an HTTP request, we can't do it synchronously, so we need to postpone Docsify initialization.

This PR allows deferring Docsify initialization by setting the window.DOCSIFY_DEFER variable. It also adds the window.runDocsify function that can be used to initialize Docsify when its config is ready.

What kind of change does this PR introduce?

Feature

For any code change,

  • Related documentation has been updated if needed
  • Related tests have been updated or tests have been added

Does this PR introduce a breaking change? (check one)

  • Yes
  • No

If yes, please describe the impact and migration path for existing applications:

Related issue, if any:

Tested in the following browsers:

  • Chrome
  • Firefox
  • Safari
  • Edge
  • IE

@vercel
Copy link

vercel bot commented May 15, 2023

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
docsify-preview ✅ Ready (Inspect) Visit Preview 💬 Add feedback Jun 9, 2023 6:23am

@codesandbox-ci
Copy link

codesandbox-ci bot commented May 15, 2023

This pull request is automatically built and testable in CodeSandbox.

To see build info of the built libraries, click here or the icon next to each commit SHA.

Latest deployment of this branch, based on commit 2674cb1:

Sandbox Source
docsify-template Configuration

@Koooooo-7 Koooooo-7 requested a review from a team May 17, 2023 15:26
@trusktr
Copy link
Member

trusktr commented Jul 4, 2023

Hello! I appreciate the idea! I think being able to load Docsify on demand is good. However I believe this isn't the direction we should go.

In the meantime you can do this:

<script type="module">
  async function loadScript(URL) {
    const code = await (await fetch(URL)).text()
    const script = document.createElement('script')
    script.textContent = code
    document.head.append(script)
  }

  async function loadDocsify() {
    await loadScript('https://unpkg.com/docsify@4')
  }

  // run this when you want
  await loadDocsify()

  console.log('Docsify is loaded')
</script>

We are recently moving all code to ESM format (PR is ready to go). Once we have that in place, we can make this easy to do in a modern way:

<script type="module">
  import {Docsify} from 'https://unpkg.com/docsify@5/lib/docsify.esm.js'

  new Docsify(container) // run this any time you want.
</script>

We're aiming to be more standards friendly and make it an HTML element a little later:

<!-- the name is up for debate -->
<docsify-element></docsify-element>

<script type="module">
  import {define} from 'https://unpkg.com/docsify@5/lib/docsify-element.js'
  define() // run this line when ready. Before then, the element will not be instantiated.
</script>

@trusktr
Copy link
Member

trusktr commented Jul 4, 2023

Thanks again @DarthSim for the idea! I will close this one, then once we merge ESM very soon let's revisit this. Totally agree it should be easy to control when Docsify loads.

@trusktr trusktr closed this Jul 4, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants