feat: allow importing runtime exports from core#3174
Conversation
7329f53 to
983e566
Compare
|
Having one import certainly makes it look cleaner! I'm worried a bit about how this affects user's. When you're inside an island, you're not supposed to import functionality that can never work there. This means we need to be either super careful about only ever referencing/exporting things that can work in both Deno and the browser. Or we would need to employ a bundler plugin to rewrite all I can certainly relate to the desire to not have to think about those things and it being easier to have only one |
That makes a lot of sense. I can think of a potential addition that could help, but maybe it's not worth the effort. But we could create a lint rule in Fresh that lints for incorrectly importing anything from I'd be happy to give it a try, and to me it makes sense if Fresh started with supplying it's own lint rules in this project (instead of bundled in Deno). // /islands/Foo.tsx
import { HttpError } from "fresh";
^^^^^^^ Importing from "fresh" is not supported in Islands and Browsers. |
|
I made #3179 as a Draft for a new base of Fresh specific lint rules. I could finish up that PR if that seems promising. |
983e566 to
e4738b3
Compare
e4738b3 to
8f92af4
Compare
|
Nice DX improvement — consolidating imports for server-side files makes sense since routes/layouts commonly need both One concern: re-exporting Would it make sense to drop Also worth noting that having two valid import paths for the same symbols ( |
fibibot
left a comment
There was a problem hiding this comment.
Mechanical re-export of asset, assetSrcSet, IS_BROWSER, Partial, and PartialProps from @fresh/core/runtime through the root entry, with call sites updated to match. CI is green across stable + canary.
- nit:
HeadandHeadPropsare the remaining runtime exports not mirrored inpackages/fresh/src/mod.ts:1— if the goal is one import for everything server-safe, they should travel with the rest.
|
@bartlomieju this is ready to merge |
This is just a potential suggestion, but I think it can be nice to just need
"fresh"to import anything needed on the server. Currently, there may be multiple import statements ("fresh"+"fresh/runtime") to get simple things from Fresh, e.g.:Given that the
@fresh/corepackage already imports from@fresh/core/runtime, I don't think this should be a regression for existing code or esbuild.graph TD; fresh <--> Server; fresh/runtime <--> Server; fresh/runtime <--> Browser["Browser (Islands)"];Though I don't know if there is a desire to avoid exports existing from multiple entrypoints, or if there is some reason JSR prevents publishing like this.