generator icon indicating copy to clipboard operation
generator copied to clipboard

[BUG] React renderer throws when a transpiled template file is missing

Open Khush7Chauhan opened this issue 1 month ago • 8 comments

Describe the bug.

In apps/react-sdk/src/renderer/template.ts, the missing-file handler resolves the promise but fails to halt execution. Because it lacks a return statement immediately after resolve(undefined);, execution continues to the next line. This causes require.resolve(componentPath) to throw an error for the missing transpiled template, turning the intended "skip missing file" behavior into an unhandled rejection. Additionally, the code currently uses a synchronous, blocking fs.existsSync call inside an asynchronous renderer.

Expected behavior

When a template file is missing, the renderer should skip it and resolve to undefined without throwing an error. The event loop should not be blocked by synchronous file system checks. A regression test running : await expect(renderTemplate(nonExistentPath, {} as any)).resolves.toBeUndefined(); should pass successfully.

Screenshots

Image

How to Reproduce

  1. Call the renderTemplate function from apps/react-sdk/src/renderer/template.ts.
  2. Pass a non-existent file path as the componentPath argument: renderTemplate('path/to/missing/file.js', {} as any).
  3. Observe that instead of resolving to undefined, the function throws an unhandled exception at the delete require.cache[require.resolve(componentPath)]; line.

🖥️ Device Information [optional]

  • Operating System (OS): Windows 11
  • Environment: Node.js
  • Browser: Brave
  • Browser Version: Latest

👀 Have you checked for similar open issues?

  • [x] I checked and didn't find similar issue

🏢 Have you read the Contributing Guidelines?

Are you willing to work on this issue ?

Yes I am willing to submit a PR!

Khush7Chauhan avatar Nov 02 '26 16:11 Khush7Chauhan

One detail matters for the regression test: importComponent calls resolve(undefined) before reaching require.resolve, and its catch calls reject(err) on that same, already-settled promise. That rejection cannot change the result, so the proposed .resolves.toBeUndefined() assertion should already pass despite the unwanted fall-through. The checked-in code therefore does not, by itself, explain an unhandled rejection. [1]

For coverage, also verify that a missing file never reaches module resolution/loading, rather than checking only the returned value. The existing renderer tests are in apps/react-sdk/src/renderer/__tests__/template.spec.ts; they currently cover single, array and async templates, but no missing-file case. [2]

This is based on source inspection; I haven’t run the reproduction.

To reply, just mention @dosu.


Docs are dead. Just use Dosu.

Leave Feedback Ask Dosu about generator Share Dosu with your team

dosubot[bot] avatar Nov 02 '26 16:11 dosubot[bot]

@dosu You're totally right about the promise settling early, meaning my original test would have just passed a false positive.I'll update the plan to use jest.spyOn(require, 'resolve') so we actually verify the code never tries to load the missing file.I've got the fix and the new test ready to go. Once a maintainer approves this issue and the proposed approach, I will open a Pull Request with the missing return statement and this updated regression test.

Khush7Chauhan avatar Nov 02 '26 17:11 Khush7Chauhan

Thanks! One caution: CommonJS require is module-scoped, so jest.spyOn(require, 'resolve') in the test file may not intercept the renderer’s own require.resolve call. That is the call the regression needs to observe. [1]

Before relying on that spy, run the new test against the unmodified implementation and confirm it fails because resolution was attempted, then passes with the early return. Otherwise, a “not called” assertion could produce another false positive. I haven’t verified the spy’s behavior in this Jest setup.

To reply, just mention @dosu.


Share context across your team and agents. Try Dosu.

Leave Feedback Learn about generator with Dosu Add Dosu to your team

dosubot[bot] avatar Nov 02 '26 17:11 dosubot[bot]

@dosu I will follow your advice and run the test against the unmodified implementation first to guarantee it actually fails. To properly intercept the resolution globally, I will spy on Node's internal Module._resolveFilename (via the module builtin) instead of the local require. I'll make sure the test definitively goes Red before it goes Green.

Khush7Chauhan avatar Nov 02 '26 18:11 Khush7Chauhan

/approve thanks @Khush7Chauhan! I checked this and it's not a bug.

If the file is missing, the code skips it and returns undefined. Yes, the missing return lets the code keep going and hit an error. But a promise only takes its first answer, so that error is ignored. Users never see it.

Before: file missing → resolve(undefined) ✅ → keeps going → error → ignored ❌ → result: undefined
After:  file missing → return resolve(undefined) ✅ → stops        → result: undefined

The result is the same, so this is a small cleanup, not a bug fix. A PR that only adds the missing returns is welcome. Please don't add tests that spy on Node internals, and don't change fs.existsSync.

Adi-204 avatar Nov 05 '26 16:11 Adi-204

hey @Khush7Chauhan maintainer adi did approve this issue, but the approval workflow only gets triggered on newly created comments and not the edited ones. So wait for him to post a new approve comment and feel free to raise a pr afterwards :)

devxdh avatar Nov 05 '26 18:11 devxdh

/approve

Adi-204 avatar Nov 05 '26 18:11 Adi-204

👋 Thanks for your patience. This issue has been reviewed and is ready to be worked on.

Before you start:

  • Comment below to let others know you're working on it (avoids duplicate work)
  • Read our CONTRIBUTING.md if you haven't already
  • Fork the repo, create a feature branch, and open a draft PR early

Approved by @Adi-204

asyncapi-bot avatar Nov 05 '26 18:11 asyncapi-bot