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

fix(git-changelog): initial dev commits not handled #245

Merged
merged 1 commit into from
Jul 8, 2024
Merged

Conversation

nekomeowww
Copy link
Member

Close #243

@nekomeowww nekomeowww added bug Something isn't working pkg/git-changelog Related to @nolebase/vitepress-plugin-git-changelog labels Jul 6, 2024
@nekomeowww nekomeowww self-assigned this Jul 6, 2024
Copy link

github-actions bot commented Jul 6, 2024

✅ Successfully deployed to Netlify

Platform Status URL
Ubuntu Success https://66896a82f28330c7734ba96c--nolebase-integrations.netlify.app
Windows Success https://66896a8d61200ed18f115177--nolebase-integrations.netlify.app

@nekomeowww nekomeowww requested a review from northword July 6, 2024 16:16
Copy link
Member

@northword northword left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good.

@northword
Copy link
Member

似乎这样可以避免 watch:

onMounted(() => {
  if (import.meta.hot) {
    import.meta.hot.send('nolebase-git-changelog:client-mounted', {
      page: {
        filePath: page.value.filePath,
      },
    })

    // Plugin API | Vite
    // https://vitejs.dev/guide/api-plugin.html#handlehotupdate
    import.meta.hot.on('nolebase-git-changelog:updated', (data) => {
      if (!data || typeof data !== 'object')
        return

      if (data.commits) {
        update(data.commits)
+++     lastChangeDate.value = toDate(commits.value[0]?.date_timestamp)
      }
    })

  ...
  }
})

onMounted(() => {
  lastChangeDate.value = commits.value[0]?.date_timestamp ? toDate(commits.value[0]?.date_timestamp) : new Date()
})

--- watch(commits, () => {
---    lastChangeDate.value = commits.value[0]?.date_timestamp ? toDate(commits.value[0]?.date_timestamp) : new Date()
---  })

另外这一段去掉后似乎也可以正常工作,它是必须的吗?

    // HMR API | Vite
    // https://vitejs.dev/guide/api-hmr.html
    import.meta.hot.accept('virtual:nolebase-git-changelog', (newModule) => {
      if (!newModule)
        return
      if (!('default' in newModule))
        return
      if (!newModule.default || typeof newModule.default !== 'object')
        return

      if (newModule.default.commits) {
        update(newModule.default.commits)
        lastChangeDate.value = toDate(commits.value[0]?.date_timestamp)
      }
    })

@nekomeowww
Copy link
Member Author

另外这一段去掉后似乎也可以正常工作,它是必须的吗?

只有在 page load 快过 git log fetch(通常出现在首次 dev server 启动)的时候才会遇到这个问题,其他时候去掉的话确实是不会有问题的,因为 git log fetch 的时候就会命中缓存了,但问题是我们不可能把 vite server 那边做成同步的会卡 transform 的。

@nekomeowww
Copy link
Member Author

似乎这样可以避免 watch

你的方法也可以,但我觉得 watch 不需要避免,就先这样吧。

@nekomeowww nekomeowww merged commit 3675781 into main Jul 8, 2024
6 checks passed
@nekomeowww nekomeowww deleted the dev/fix-lang branch July 8, 2024 05:13
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working pkg/git-changelog Related to @nolebase/vitepress-plugin-git-changelog
Projects
None yet
Development

Successfully merging this pull request may close these issues.

bug (git-changelog, enhanced-readabilities): Problems with localization in vitepress dev
2 participants