histoire-dev / histoire-dev/histoire

Links in markdown files depend on the resolve order

Open
#562 1 comment 1 reaction 0 assignees View on GitHub
to triage
Dominant language
TypeScript
Stars
3.6k
Forks
212
PR merge metrics
No merged PRs in 30d

Description

### Describe the bug

Good evening!
I have noticed that histoire build will fail if you have a link which references a file which is not in the ctx yet. Consider these two files:
`src/file1.story.md`
```md
---
title: Docs/File1
id: file1
---

- [Link to file 2](./forContributors/file2.story.md)
```
`src/file2.story.md`
```md
---
title: Docs/File2
id: file2
---

- [Link to file 1](../file1.story.md)
```

If I run `histoire dev` (or `build` - it doesn't matter), I get the following error:
```
Error: [md] Cannot find story file: ./file2.story.md from /home/projects/histoire-vue3-starter-jpcz1f/src/file1.story.md
at md.renderer.rules.link_open (file:///home/projects/histoire-vue3-starter-jpcz1f/node_modules/histoire/dist/node/markdown.js:79:31)
at Renderer.renderInline (file:///home/projects/histoire-vue3-starter-jpcz1f/node_modules/markdown-it/lib/renderer.js:275:28)
at Renderer.render (file:///home/projects/histoire-vue3-starter-jpcz1f/node_modules/markdown-it/lib/renderer.js:330:22)
at MarkdownIt.render (file:///home/projects/histoire-vue3-starter-jpcz1f/node_modules/markdown-it/lib/index.js:544:24)
at addFile (file:///home/projects/histoire-vue3-starter-jpcz1f/node_modules/histoire/dist/node/markdown.js:147:25)
at async FSWatcher.eval (file:///home/projects/histoire-vue3-starter-jpcz1f/node_modules/histoire/dist/node/markdown.js:203:9)
```

After a small research I have found that the problem was that markdown-it for file1 starts running `link_open` rule before actually finishing collecting all the `.md` files from the `.md` watcher. For simplicity I have attached a repro in Stackblitz

### Reproduction

https://stackblitz.com/edit/histoire-vue3-starter-jpcz1f?file=src%2Ffile2.story.md,src%2Ffile1.story.md

### System Info

```shell
System:
OS: macOS 13.3.1
CPU: (10) arm64 Apple M1 Pro
Memory: 64.95 MB / 16.00 GB
Shell: 3.5.1 - /opt/homebrew/bin/fish/
Binaries:
Node: 16.20.1 - /opt/homebrew/opt/node@16/bin/node
Yarn: 1.22.19 - /opt/homebrew/bin/yarn
npm: 8.19.4 - /opt/homebrew/opt/node@16/bin/npm
pnpm: 8.6.6 - /opt/homebrew/bin/pnpm
Browsers:
Chrome: 115.0.5790.102
Safari: 16.4
```

### Used Package Manager

npm

### Validations

- [X] Follow our [Code of Conduct](https://github.com/histoire-dev/histoire/blob/main/CODE_OF_CONDUCT.md)
- [X] Read the [Contributing Guidelines](https://github.com/histoire-dev/histoire/blob/main/CONTRIBUTING.md).
- [X] Read the [docs](https://histoire.dev/guide/).
- [X] Check that there isn't [already an issue](https://github.com/histoire-dev/histoire/issues) that reports the same bug to avoid creating a duplicate.
- [X] Check that this is a concrete bug. For Q&A open a [GitHub Discussion](https://github.com/histoire-dev/histoire/discussions).
- [X] The provided reproduction is a [minimal reproducible example](https://stackoverflow.com/help/minimal-reproducible-example) of the bug.

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.