photogabble / eleventy-plugin-interlinker

Adds wikilink and wikilink embed support with tracking of backlinks.
https://photogabble.co.uk/projects/eleventyjs-interlink-plugin/
MIT License
17 stars 1 forks source link

CRASH: change to wikilink embed reference with 11ty in serve mode results in crash #33

Closed carbontwelve closed 4 months ago

carbontwelve commented 4 months ago

When running 11ty in serve mode and making a change to a wikilink reference that prompts a rebuild the entire process crashes.

[11ty] Cannot read properties of undefined (reading 'compileOptions') (via TypeError)
[11ty] 
[11ty] Original error stack trace: TypeError: Cannot read properties of undefined (reading 'compileOptions')
[11ty]     at CustomEngine.shouldSpiderJavaScriptDependencies (/Users/simon/Code/photogabble/website/node_modules/@11ty/eleventy/src/Engines/Custom.js:289:13)
[11ty]     at EleventyExtensionMap.shouldSpiderJavaScriptDependencies (/Users/simon/Code/photogabble/website/node_modules/@11ty/eleventy/src/EleventyExtensionMap.js:130:32)
[11ty]     at /Users/simon/Code/photogabble/website/node_modules/@11ty/eleventy/src/EleventyFiles.js:343:27
[11ty]     at Array.filter (<anonymous>)
[11ty]     at EleventyFiles.getWatchPathCache (/Users/simon/Code/photogabble/website/node_modules/@11ty/eleventy/src/EleventyFiles.js:340:27)
[11ty]     at Eleventy._initWatchDependencies (/Users/simon/Code/photogabble/website/node_modules/@11ty/eleventy/src/Eleventy.js:940:44)
[11ty]     at Eleventy._watch (/Users/simon/Code/photogabble/website/node_modules/@11ty/eleventy/src/Eleventy.js:833:16)
[11ty]     at async watchRun (/Users/simon/Code/photogabble/website/node_modules/@11ty/eleventy/src/Eleventy.js:1047:9)
[11ty]     at async FSWatcher.<anonymous> (/Users/simon/Code/photogabble/website/node_modules/@11ty/eleventy/src/Eleventy.js:1065:7)

To clarify, this was when I was loading ![[ Building a self-contained game in C# under 2 kilobytes ]] resulting in a broken embed, when I amended it to escape the # the above crash happened during rebuild.

carbontwelve commented 4 months ago

This is likely to be fixed by #34. What I suspect to be happening is the compileOptions is part of interlinker.templateConfig set when 11ty triggers the eleventy.config event. However when a new build begins that might be getting deleted or something along those lines. I'd chuck a debugger on the process to watch it happen during a build.

carbontwelve commented 4 months ago

34 didn't fix the issue, this seems to be an internal issue with the RenderManager class internal to 11ty.

Within the Render Plugin it will ignore templateConfig passed through to the compile function and set it from this: see source.

This works the first time 11ty builds, but subsequent builds with --watch cause the issue. I have been able to fix this in my website by modifying the interlinker plugin with the following:

  eleventyConfig.on("eleventy.config", (cfg) => {
    interlinker.templateConfig = cfg;
    if (interlinker.rm) interlinker.rm.templateConfig = cfg;
  });

This ensures that the RenderManager is using the current template config.

Alternatively, instead of using the render plugin in a "hacky" way it might be possible to copy https://github.com/11ty/eleventy/blob/main/src/Plugins/RenderPlugin.js#L20-L52 into interlinker and forego the need to jury rig stuff.