-
-
Notifications
You must be signed in to change notification settings - Fork 2.5k
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
Fix: Removes a misleading log message telling that a custom renderer is not recognized while it clearly is. Adding a new example to demo custom renderers for prove. #12461
base: main
Are you sure you want to change the base?
Conversation
…atic list of renderers while Astro allows to dynamically add custom renderers
… renderers with the log message fixed
…nce (real-world use)
🦋 Changeset detectedLatest commit: b9f2d45 The changes in this PR will be included in the next version bump. Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
We usually use examples for beginners who want to start from somewhere. Having a custom renderer is not a beginner example, so I don't think we should have it. Instead, we should have tests that cover the new changes. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would remove the example and add a new test
@ematipico Right, I was foreseeing this argument somehow :)) I'll take the example code and put it in a new repo under my Github account. People who plan to implement their own custom renderers would be able to find our conversation, and start from there. I'll also add a test to verify my changes, but due to the nature of the issue, I need to temporarily hook the console.warn function in order to prove that the log is not written anymore. |
If that can help, in this commit I removed a patch to intercept console logs. Maybe you can reuse it in some way |
Moved the example code for a custom renderer / custom frontend framework integration over here: https://github.com/kyr0/astro-custom-renderer |
CodSpeed Performance ReportMerging #12461 will not alter performanceComparing Summary
|
If you plan to advertise your custom renderer example, I would suggest to change the entry points to use a valid extension. Currently they don't have one, which is invalid in Node.js. Every import must have a file extension. In fact, even our container API suggests the use of the extension |
it('does not log a warning message when using a custom renderer', async () => { | ||
const res = await fixture.fetch('/'); | ||
assert.equal(res.status, 200); | ||
|
||
assert.equal( | ||
warnLogsWritten.indexOf( | ||
'If you intended to use a different renderer, please provide a valid client:only directive.', | ||
), | ||
-1, | ||
); | ||
}); | ||
}); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think I'd prefer removing this test since it's only guarding if we ever revert this PR, which if we do we probably have a good reason for it. That way we also avoiding patching console.warn
for this test.
The other test cases are fine to keep though, we're lacking tests for custom renderers.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@bluwy I agree, but then I cannot test if the change actually works. When I don't test this behaviour change -- then why add tests? On the other hand I'm personally absolutely fine with not testing removing a console.log
:) There's really not much that can go wrong
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I personally would be fine if the PR didn't have tests in the first place, like you mentioned, it's only a console.log. But since the work is already done testing with a custom renderer, I think it's valuable to preserve that.
If the warning message we're trying to check to never be log never exists in the source code after the PR is merged, then it's very unlikely that test will fail again. If some feature were to be brought back, the warning message will likely be different. If it's the same, it's likely a revert where (as I mentioned above) if we did that there's probably a good reason so and the test would've been removed.
The reason why it's actually not that technically "invalid" in this specific case, and worked (even if it looks a bit invalid, I agree!) was that this project uses TypeScript path aliases, as defined in the At transpile/bundle ("compile") time, during development, Vite uses Because the code generation is on-the-fly in this case, the change you requested, is not as easy as simply adding a Changing this (not relying on path aliases) requires a major rework of the example, now with a monorepo structure where the renderer would get its own package, exports, dist build output, and the actual astro example could depend on it. Because Vite would be able to load the built dist files of the module, loading the entrypoints with a It makes sense to implement this structural change, also, because most developers who'd plan to implement their custom renderers or framework integrations wouldn't do it inside of an example Astro project repository. I just thought the example would look way easier without a more complicated monorepo setup. But I agree that in this case, correctness is much more important. edit: Refactoring done: https://github.com/kyr0/astro-custom-renderer Using |
Changes
Removes the misleading log message telling that a custom renderer is not recognized while it clearly is and works.
Also adds a framework-custom example that demonstrates how to write custom renderers.
The example proves that custom renderers work well with the change.
Before:
After:
Fixes: #12463
The only change that is Astro core related is:
https://github.com/withastro/astro/pull/12461/files#diff-f28699aad5f8ec8f0ab34b5e512b815bf3088a32898cbeb1368b6be5d27a9813
It should be safe to merge, because no logic other than a log message is affected.
Testing
pnpm --filter @example/framework-custom run dev
Enjoy! :)
Docs
I don't think that this use-case is relevant to most developers. This is a change that affects the flexibility of Astro to welcome and accept custom framework / custom markup implementations. Whoever is interested in building such advanced integrations, will probably take a look at the code first and find the new example that comes with this PR which clearly demonstrates how to do so.