server-side functions are sometimes undefined

Open
#117 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Assessment

Difficulty
4/5
Estimated time
3-5 days
Newbie friendliness
35/100
Issue type
Bug
Clarity
Mostly clear
Activity status
Stale
Tech stack
typescript
Domain
backend

Research direction

Start with server/main.ts and src/main.tsx, tracing how foo is imported and accessed from the custom post renderer. Reproduce the example repeatedly and inspect the relevant build or runtime behavior. Done means the function is consistently available where the issue expects it, with a regression test or documented limitation if that is not possible.

Written by the indexing model from the issue text.

Description

for some reason, the following snippets of code sometimes log [Function: foo] (as expected) and sometimes log undefined

// file: ./server/main.ts

export function foo(): string {
    return "bar";
}
// file: ./src/main.tsx

import { Devvit } from "@devvit/public-api";
import { foo } from "../server/main.js";

Devvit.configure({
    redditAPI: true,
});

Devvit.addMenuItem({
    label: "Create minigames post",
    location: "subreddit",
    forUserType: "moderator",
    onPress: async (_event, { reddit, ui }) => {
        await reddit.submitPost({
            title: "title",
            subredditName: (await reddit.getCurrentSubreddit()).name,
            preview: (
                <vstack height="100%" width="100%" alignment="middle center">
                    <text size="large">Loading...</text>
                </vstack>
            ),
        });
        ui.showToast({ text: "Created post!" });
    },
});

Devvit.addCustomPostType({
    name: "Experience Post",
    render: _context => {
        console.log(foo); // sometimes logs [Function: foo] and sometimes logs undefined
        return <text>lorem ipsum dolor sit amet</text>;
    },
});

export default Devvit;
Dominant language
TypeScript
Stars
210
Forks
88
PR merge metrics
No merged PRs in 30d

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from reddit/devvit

All issues in reddit/devvit

Similar issues

More TypeScript issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.