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

ReferenceError if editLink callable calls another function #4611

Closed
4 tasks done
lukasberbuer opened this issue Mar 9, 2025 · 1 comment
Closed
4 tasks done

ReferenceError if editLink callable calls another function #4611

lukasberbuer opened this issue Mar 9, 2025 · 1 comment
Labels

Comments

@lukasberbuer
Copy link

Describe the bug

I want to use a function within the editLink pattern callable. This results in a ReferenceError:

A `ReferenceError`: getEditLinkPattern is not defined at eval (eval at deserializeFunctions (@siteData:1:228), <anonymous>:4:9)

Reproduction

function getEditLinkPattern(payload: PageData) {
  return "https://github.com/vuejs/vitepress/edit/main/docs/:path";
}

export default {
  themeConfig: {
    editLink: {
      pattern: (payload) => {
        return getEditLinkPattern(payload);
      },
      text: 'Edit this page on GitHub'
    }
  }
}

Expected behavior

The callable in editLink.pattern should be able to reference other functions.

System Info

System:
    OS: Windows 11 10.0.26100
    CPU: (16) x64 AMD Ryzen 7 PRO 7840U w/ Radeon 780M Graphics  
    Memory: 15.65 GB / 30.67 GB
  Binaries:
    Node: 22.14.0 - C:\Program Files\nodejs\node.EXE
    npm: 10.9.2 - C:\Program Files\nodejs\npm.CMD
  Browsers:
    Edge: Chromium (131.0.2903.99)
    Internet Explorer: 11.0.26100.1882
  npmPackages:
    vitepress: ^1.6.3 => 1.6.3

Additional context

No response

Validations

@lukasberbuer lukasberbuer added the bug: pending triage Maybe a bug, waiting for confirmation label Mar 9, 2025
@brc-dd brc-dd added wont fix and removed bug: pending triage Maybe a bug, waiting for confirmation labels Mar 9, 2025
@brc-dd
Copy link
Member

brc-dd commented Mar 9, 2025

Only "pure" functions are supported - they shouldn't reference any variable outside their scope.

You can also put a pure function that accepts [`PageData`](./runtime-api#usedata) as the argument and returns the URL string.

It should not have side-effects nor access anything outside of its scope since it will be serialized and executed in the browser.

@brc-dd brc-dd closed this as not planned Won't fix, can't repro, duplicate, stale Mar 9, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants