Skip to content

Commit

Permalink
fix: local islands treated as server components (#1195)
Browse files Browse the repository at this point in the history
  • Loading branch information
marvinhagemeister authored Sep 4, 2023
1 parent 975016d commit ae1debf
Showing 1 changed file with 10 additions and 5 deletions.
15 changes: 10 additions & 5 deletions src/rules/fresh_server_event_handlers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -50,12 +50,12 @@ impl Handler for Visitor {
ctx: &mut Context,
) {
// Fresh only considers components in the routes/ folder to be
// server components.
// server components. Files inside an `(_islands)` folder are considered
// islands though, even if they are inside the `routes` folder.
let path = Path::new(ctx.file_name());
if !path
.components()
.map(|comp| comp.as_os_str())
.any(|comp| comp == "routes")
let mut path_component = path.components().map(|comp| comp.as_os_str());
if !path_component.any(|comp| comp == "routes")
|| path_component.any(|comp| comp == "(_islands)")
{
return;
}
Expand Down Expand Up @@ -166,6 +166,11 @@ mod tests {
"<x-foo onClick=\"console.log('hey')\" />",
"foo.jsx",
);
assert_lint_ok(
&FreshServerEventHandlers,
"<button onClick={function () {}} />",
"routes/foo/(_islands)/foo.jsx",
);

assert_lint_err!(FreshServerEventHandlers, filename: "routes/index.tsx", r#"<button onClick={() => {}} />"#: [
{
Expand Down

0 comments on commit ae1debf

Please sign in to comment.