MCPcopy Create free account
hub / github.com/react-static/react-static / registerTemplates

Function registerTemplates

packages/react-static/src/browser/index.js:54–92  ·  view source on GitHub ↗
(tmps, notFoundKey)

Source from the content-addressed store, hash-verified

52onReloadTemplates.listeners = []
53
54export const registerTemplates = async (tmps, notFoundKey) => {
55 Object.keys(templatesByPath).forEach(key => {
56 delete templatesByPath[key]
57 })
58 Object.keys(templateErrorByPath).forEach(key => {
59 delete templateErrorByPath[key]
60 })
61 Object.keys(templates).forEach(key => {
62 delete templates[key]
63 })
64 Object.keys(tmps).forEach(key => {
65 templates[key] = tmps[key]
66 if (!templates[key]) {
67 console.warn(
68 `Template registered without default export: ${key.replace(
69 /__react_static_root__\//,
70 ''
71 )}`
72 )
73 }
74 })
75 templatesByPath[PATH_404] = templates[notFoundKey]
76
77 if (
78 process.env.NODE_ENV === 'development' &&
79 typeof document !== 'undefined'
80 ) {
81 await prefetch(window.location.pathname)
82 }
83
84 onReloadTemplates.listeners.forEach(fn => fn())
85
86 if (
87 typeof document !== 'undefined' &&
88 process.env.REACT_STATIC_SILENT !== 'true'
89 ) {
90 console.log('React Static: Templates Reloaded')
91 }
92}
93
94export const registerTemplateForPath = (path, template) => {
95 path = getRoutePath(path)

Callers 1

Calls 1

prefetchFunction · 0.85

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…