Skip to content

Commit

Permalink
Merge branch 'canary' into 36247
Browse files Browse the repository at this point in the history
  • Loading branch information
kodiakhq[bot] committed Apr 19, 2022
2 parents 3c8a5f6 + deb8280 commit 98b5887
Show file tree
Hide file tree
Showing 4 changed files with 45 additions and 4 deletions.
2 changes: 2 additions & 0 deletions docs/basic-features/script.md
Expand Up @@ -256,6 +256,8 @@ export default function Home() {
}
```

> **Note: `onLoad` can't be used with the `beforeInteractive` loading strategy.**
Sometimes it is helpful to catch when a script fails to load. These errors can be handled with the `onError` property:

```jsx
Expand Down
26 changes: 22 additions & 4 deletions packages/next-swc/crates/core/src/next_ssg.rs
Expand Up @@ -13,6 +13,8 @@ use swc_ecmascript::{
visit::{noop_fold_type, Fold},
};

static SSG_EXPORTS: &[&str; 3] = &["getStaticProps", "getStaticPaths", "getServerSideProps"];

/// Note: This paths requires running `resolver` **before** running this.
pub fn next_ssg(eliminated_packages: Rc<RefCell<FxHashSet<String>>>) -> impl Fold {
Repeat::new(NextSsg {
Expand Down Expand Up @@ -55,9 +57,7 @@ struct State {
impl State {
#[allow(clippy::wrong_self_convention)]
fn is_data_identifier(&mut self, i: &Ident) -> Result<bool, Error> {
let ssg_exports = &["getStaticProps", "getStaticPaths", "getServerSideProps"];

if ssg_exports.contains(&&*i.sym) {
if SSG_EXPORTS.contains(&&*i.sym) {
if &*i.sym == "getServerSideProps" {
if self.is_prerenderer {
HANDLER.with(|handler| {
Expand Down Expand Up @@ -132,12 +132,30 @@ impl Fold for Analyzer<'_> {

fn fold_export_named_specifier(&mut self, s: ExportNamedSpecifier) -> ExportNamedSpecifier {
if let ModuleExportName::Ident(id) = &s.orig {
self.add_ref(id.to_id());
if !SSG_EXPORTS.contains(&&*id.sym) {
self.add_ref(id.to_id());
}
}

s
}

fn fold_export_decl(&mut self, s: ExportDecl) -> ExportDecl {
if let Decl::Var(d) = &s.decl {
if d.decls.is_empty() {
return s;
}

if let Pat::Ident(id) = &d.decls[0].name {
if !SSG_EXPORTS.contains(&&*id.id.sym) {
self.add_ref(id.to_id());
}
}
}

s.fold_children_with(self)
}

fn fold_expr(&mut self, e: Expr) -> Expr {
let e = e.fold_children_with(self);

Expand Down
@@ -0,0 +1,16 @@
export const revalidateInSeconds = 5 * 60;

export const getStaticProps = async () => {
return {
props: {},
revalidate: revalidateInSeconds,
};
};

export default function Home({}) {
return (
<div>
<p>Hello World</p>
</div>
)
}
@@ -0,0 +1,5 @@
export var __N_SSG = true;
export const revalidateInSeconds = 5 * 60;
export default function Home({}) {
return __jsx("div", null, __jsx("p", null, "Hello World"));
};

0 comments on commit 98b5887

Please sign in to comment.